Move Randomly in 1 of 8 directions

0 favourites
  • 3 posts
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • 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 <img src="smileys/smiley1.gif" border="0" align="middle"> ! Thanks in advance for any help!

  • Try this:

    45 * int(random(0,7))

    I think something like this should help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Try this:

    45 * int(random(0,7))

    I think something like this should help!

    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 <img src="smileys/smiley4.gif" border="0" align="middle" /> !

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)