how to make something move randomly?

DarDar Member Posts: 37
edited November -1 in Working with GS (Mac)
Hello,

In my game I want it so when my shark touches the fish,i want the fish to move away to a new random position and then the shark goes there it moves away to somewhere else...

how can I do this?

Thanks so much! :c )

Comments

  • DarDar Member Posts: 37
  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    You would use the random function in the expression editor combined with a couple rules.

    Create a rule inside the fish actor:

    When actor overlaps or collides with actor shark
    --interpolate self.position.x to random(40, 440)
    duration .5
    --interpolate self.position.y to random(40, 280)
    duration .5

    Interpolate will change any attribute from one thing to another and will take however long you specify to change. It is an AMAZING tool!

    The random function will pick a random number between the 2 numbers you specify, in this case, 40 and 280. You have to use the expression editor in order for the random function to work! Just click the little "e" next to the text box and select random, then fill in the 2 numbers!

    Hope this helps!

    -Kyle
  • RHRH Member Posts: 1,079
    You can use move to or interpolate. For the X and Y location use the random function. For example:

    Rule(on the fish): When actor overlaps or collides with actor of type shark

    Move to: X:randon(0,480) Y:random(0,320) relative to: scene
    speed:???
  • DarDar Member Posts: 37
    oh thanks! I understand!!

    thanks so much!
  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    Interpolate can be used for a lot of things too such as increasing/decreasing the size of an actor or changing the alpha to 0 over a set amount of time (to make the actor fade).

    Great tool to use!
  • CapCap Member Posts: 225
    iPhoneDevForMe said:
    Interpolate can be used for a lot of things too such as increasing/decreasing the size of an actor or changing the alpha to 0 over a set amount of time (to make the actor fade).

    Great tool to use!

    Hm, I do all this NOT with interpolate, as I thought using interpolate would need too much resources (like constrain behaviour or too many timers). I also thought it would be difficult to implement a pause system then. Am I wrong on that one?
    What's the best use for interpolate, why should you use it / not use it (if you want to create games for iPhone, also the 2G/3G)?
Sign In or Register to comment.