How do I a random move using the 8 direction?

Get help using Construct 2

Post » Sat Jul 04, 2015 1:46 am

Please? :D Using animations for each direction.
B
6
Posts: 15
Reputation: 287

Post » Sat Jul 04, 2015 3:52 am

Create an instance variable called "Direction".
Then have an event that performs the action on the instance variable "set value" and type in "floor(random(1,9))". This generates a random number between 1 and 9 (not including 9) and then rounds it to the lowest integer, giving you a whole number between 1 and 8 (including both 1 and 8). Then you'll need an event that checks this instance variable and if it is 1 performs the action "simulate control: right" (The 'right' option appears after you select the 'simulate control' action).

You'll actually need 8 different events with each one checking for a different number. Each event's will then do the "simulate control" action. For the diagonal directions, you'll have 2 actions. For example, if 2 is the number generated, then your event checking to see if the number is 2 will have one action for "Simulation control: right" and another for "simulation control: down", and your object will move down and right.

An additional action for each event would be to set the animation sprite to a certain frame (or animation) for each number. I don't know the details of your game, so I can't give you a specific way of setting this up. It depends on what the object is doing, when/why it changes direction, etc.
B
8
S
2
Posts: 35
Reputation: 572

Post » Sun Jul 05, 2015 1:01 pm

Which event I create to check, I kind of lost myself here. Sorry.
B
6
Posts: 15
Reputation: 287

Post » Tue Jul 07, 2015 2:14 am

It's just a basic event. If sprite's instance variable is 1, then perform action X.
B
8
S
2
Posts: 35
Reputation: 572

Post » Tue Jul 07, 2015 5:38 am

Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Wed Jul 08, 2015 6:25 pm

deathangel Thank you man. :))))
B
6
Posts: 15
Reputation: 287


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, Nicolas951, Shenkai the ssj and 25 guests