velocity attribute + random spawn around screen

mr_potatomr_potato Member Posts: 22
edited June 2014 in Working with GS (PC)

Hey there, straight to it. say i have actor a and an actor b i have actor b constrained to the very middle of the scene editor and i want actor a to come in from a random spot outside of the scene editor moving at a constant rate towards actor b.
even further. i want there to be an unlimited amount of actor a's coming from random places from outside of the scene editor at random times. all moving towards actor b. Can anyone help me with this?

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    Hi @mr_potato‌ and welcome to the GameSalad Forums.

    The following is untested but should work (and it's also assuming your actor a doesn't move - although I'm guessing it might rotate):

    P.S The rules I've shown here are for the Mac version of GSC using that terminology -so need a little bit of "translation" for your PC version ("Do", etc....)

    • Make two game integer attributes, let' call them Ax and Ay. Make their values the x and y coords. of actor A.

    • Make another integer attribute, call it SideRand

    • Make yet another integer and call it TimeEvery -set its initial value to the delay of each
      spawned actor B, i.e if you want them spawning every 5 seconds, make its value 5 --

    • Two more integer attributes, called BBX and BBY

    • Make a final integer Attribute, called BActAngle


    Put the following in a blank actor somewhere outside of the screen area.

        Rule: When scene.GoB is true --- don't include if you want 
    -- the process to start straightaway; but if you do, 
    --put in a Go button or similar: Change Attribute Go to true --
        Timer: Every scene.TimeEvery
        Spawn ActorB
    

    Now in the rules of Prototype of ActorB, in the Inspector, put:

        Change Attribute SideRand to random(1,2)
    
    
     Rule: When SideRand = 1
           Change Attribute self.Position.X to -60
         Change Attribute BBX to -60
            Otherwise
            When SideRand = 2
            Change Attribute self.Position.X to -- this number to be 
        --the width of your screen + at least half the width of ActorB --
             Change Attribute BBX to ??
    
            Change Attribute SideRand to random(1,2)
    
        Rule: When SideRand = 1
        Change Attribute self.Position.Y to -- this number to be 
    --the height of your screen + at least half the width of ActorB --
         Change Attribute BBY to ??
        Otherwise
        When SideRand = 2
        Change Attribute self.Position.Y to -60
     Change Attribute BBY to -60
    
    Change Attribute BActAngle to vectorToAngle(BBX-Ax,BBY-By)
    
    Change Velocity 
    Direction: scene.BActAngle Relative to: scene
    Speed: --whatever you require.
    

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mr_potatomr_potato Member Posts: 22

    Hey thanks for this will try now :)

  • mr_potatomr_potato Member Posts: 22

    hey. @Gyroscope in the rules of actor prototype b when you say 'otherwise' is that a new rule or is it just another 'change attribute' behaviour?

  • mr_potatomr_potato Member Posts: 22

    also what is ' change attribute bbx to ??' and ' change attribute bby to ??'

    and at the bottom i cant seem to find scene. angle

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    @mr_potato said:
    hey. Gyroscope in the rules of actor prototype b when you say 'otherwise' is that a new rule or is it just another 'change attribute' behaviour?

    Hi, I don't use the Windows GSC version so can't remember to tell you what "Otherwise" is called on your version.... it's whatever the equivalent of "Otherwise" is as part of the same rule (Do).... hope I've explained myself clearly enough...

    (Perhaps some one else could chime in here to remind me of the "Otherwise" PC GSC version word...

    @mr_potato said:
    also what is ' change attribute bbx to ??' and ' change attribute bby to ??'

    and at the bottom i cant seem to find scene. angle

    • The question marks are because the numbers will be different depending on what size screen you are using... I did give an explanation in the programming suggestion, but I'll explain again...

    So you work out the following numbers: the width of your screen + at least half the width of your actorb, that'll be the number for " Change Attribute BBX to ??"

    Similar for "Change Attribute BBY to ??" the ?? you replace with a number which is the height of your screen + at least half the height of your actor

    Both of those two are to ensure your spawned actor b appears outside of the screen at the top or at the right hand side. (For the left and bottom sides, I simply guises the number -60 in both cases, i.e assuming your actor b isn't anymore wider than 120 pxls)

    • As for the attribute Angle, I suggested you make that as an integer at the beginning of the explanation.

    Hope that sorts it for you....


    Edit: I did think at the time I shouldn't be making the name of an integer attribute the same as another type of attribute (i.e an angle type attribute) as I thought it might cause confusion (which it did!)... but I went ahead anyway....

    For clarity sake then, let's change the name of the integer attribute I called Angle, to BActAngle. I'll amend the above rules accordingly for you so it's clearer.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mr_potatomr_potato Member Posts: 22

    just re- read the start of your initial comment and my actor a is the one that is moving towards actor b, and actor b is stationary. but i want there to be an unlimited amount of actor a's to be spawning from outside the screen at random positions at random times heading towards actor b

  • mr_potatomr_potato Member Posts: 22
  • SocksSocks London, UK.Member Posts: 12,822

    @mr_potato said:

    Here's another way of doing it . . .

    Link: https://www.mediafire.com/?2ac3w5kso27c77w

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    @mr_potato said:
    just re- read the start of your initial comment and my actor a is the one that is moving towards actor b, and actor b is stationary. but i want there to be an unlimited amount of actor a's to be spawning from outside the screen at random positions at random times heading towards actor b

    Oh, yes, sorry, got them around the wrong way round! Here it is again with easy amendments:


    • Make two game integer attributes, let' call them Bx and By. Make their values the x and y coords. of actor B.

    • Make another integer attribute, call it SideRand

    • Make yet another integer and call it TimeEvery -set its initial value to the delay of each
      spawned actor A, i.e if you want them spawning every 5 seconds, make its value 5 --

    • Two more integer attributes, called ABX and ABY

    • Make a final integer Attribute, called AAng


    Put the following in a blank actor somewhere outside of the screen area.

        Rule: When scene.GoA is true --- don't include if you want 
    -- the process to start straightaway; but if you do, 
    --put in a Go button or similar: Change Attribute Go to true --
        Timer: Every scene.TimeEvery
        Spawn ActorA
    

    Now in the rules of Prototype of ActorA, in the Inspector, put:

        Change Attribute SideRand to random(1,2)
    
    
     Rule: When SideRand = 1
           Change Attribute self.Position.X to -60
         Change Attribute ABX to -60
            Otherwise
            When SideRand = 2
            Change Attribute self.Position.X to -- this number to be 
        --the width of your screen + at least half the width of ActorA --
             Change Attribute ABX to ??
    
            Change Attribute SideRand to random(1,2)
    
        Rule: When SideRand = 1
        Change Attribute self.Position.Y to -- this number to be 
    --the height of your screen + at least half the width of ActorA --
         Change Attribute ABY to ??
        Otherwise
        When SideRand = 2
        Change Attribute self.Position.Y to -60
     Change Attribute ABY to -60
    
    Change Attribute AAng to vectorToAngle(ABX-Bx,ABY-By)
    
    Change Velocity 
    Direction: scene.AAng Relative to: scene
    Speed: --whatever you require.
    

    Or use @Socks' method... :wink:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mr_potatomr_potato Member Posts: 22

    OMG @socks thankyou so much. plus @gyroscope thankyou you so much for your help but because im new here some of your wording didnt get through to me thankyou both so much

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    @mr_potato said:
    OMG socks thankyou so much. plus gyroscope thankyou you so much for your help but because im new here some of your wording didnt get through to me thankyou both so much

    You're welcome; and glad it will help you; best of luck with all your future game-making endeavours. :smile:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mr_potatomr_potato Member Posts: 22

    Hi there @socks, i have been working on my project that used the link that you sent. Now i am partially finished. but what i want to know is if it can only be used on an ipad or multiple apple devices. If it is only compatible for an ipad how can i change it to iphone so i can reach a larger customer audience, I have previously tried to add everything ( attributes, rules etc) into an iphone template but i have had no success.

Sign In or Register to comment.