How do I choose random animation?

Get help using Construct 2

Post » Fri Jun 19, 2015 10:52 am

I'd like to use random animation of my sprite when overlapping other object... For example randomly kick or punch animations. Thanks!
B
10
S
1
Posts: 49
Reputation: 600

Post » Fri Jun 19, 2015 11:18 am

You can either way:

1. Create a variable to work as your random number, and then set the animation to happen based on that variable.
For instance, A = int(random(3)) . If A = 0 play animation "Punching", if A = 1 play animation "Kicking" and so on.

or

2. Set the name of all animations you want to happen randomly the same. Like, RandomAnimation1, RandomAnimation2, RandomAnimation3... you got my point.
With all the names the same try this:
On overlapping object > Set animation to "RandomAnimation" & intRandom(3)

Hope this helps
B
17
S
7
Posts: 280
Reputation: 2,522

Post » Fri Jun 19, 2015 11:21 am

Or use

On overlapping object > Set animation to : choose("kicking","Punching")
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jun 19, 2015 11:22 am

play animation : choose("kick","punch","duck","fall")


choose("item1","item2",etc) will pick one of its items randomly.


Edit: ninja'd by littlestain :lol:
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri Jun 19, 2015 11:31 am

I see one issue though, the choosing will be performed every tick, so the animation could change every tick..

It would probably be better to set an (instance) variable to choose() on collision and play animation = (instance) variable when overlapping...
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jun 19, 2015 11:32 am

Thanks to all! "choose" function is perfect!
B
10
S
1
Posts: 49
Reputation: 600


Return to How do I....?

Who is online

Users browsing this forum: dand, R0J0hound and 20 guests