Move Randomly in 1 of 8 directions

Get help using Construct 2

Post » Sat Mar 30, 2013 3:12 am

Hello there, at the moment I am trying to figure out how to make an object move in 1 of 8 random directions on key release. The object is a ball, one that uses bullet behavior to effect its movement. The direction I need to move the ball in are 0(360?),45,90,135,180,225,270,315(for example).
I need this ball to randomly go in one of these said directions on ever key release. I am currently using the random(360) expression for the sake of moving along, but it would be more fitting of the mechanics I am aiming for to have the ball move in only 8 possible directions. Any help would greatly be appreciated ! Thanks in advance for any help!
B
3
Posts: 2
Reputation: 629

Post » Sat Mar 30, 2013 3:17 am

Try this:
45 * int(random(0,7))

I think something like this should help!
B
13
S
4
Posts: 117
Reputation: 2,242

Post » Sat Mar 30, 2013 4:14 am

[QUOTE=Zero6] Try this:
45 * int(random(0,7))

I think something like this should help![/QUOTE]

Thank You very much for the quick response! This did work, though I had to change it to (0,8) to have the ball go towards a up and right angle.

Your help is greatly appreciated !
B
3
Posts: 2
Reputation: 629


Return to How do I....?

Who is online

Users browsing this forum: h1k3, Yahoo [Bot] and 18 guests