help in randomized rotation

Get help using Construct 2

Post » Fri Nov 08, 2013 1:11 pm

hello world,
i have a game, in which i need every object in the layout to rotate around the center ( which i have figured out, using the pin behaviour). i really need help to make the directions of rotating and amount of rotations randomized.

eg. the objects will rotate 3 times to the right, then 5 to the left, then 2 to the right.

i have tried a lot , but nothing works...

thanks.
B
20
S
8
G
2
Posts: 122
Reputation: 3,202

Post » Fri Nov 08, 2013 1:38 pm

One way I can think of is having an invisible sprite that each object will pass on each rotation. Then when you create your objects, they have instance variable like rotationTime. Give it a random number after you create the object int(random(2,6)).

Then each time the object collides with the invisible sprite first subtract 1 from rotationTime. Then check to see if it's 0, if it is, reverse the rotation and give rotationTime a new random number.

B
101
S
32
G
11
Posts: 1,546
Reputation: 21,667

Post » Fri Nov 08, 2013 2:29 pm

let's say your mid is 250, 250, then rotating your objects around it would look like this:

2 instance variables for your sprites: ccc and speed. Speed = the angle difference each step. ccc decides the direction.

code:
system every 0.2 seconds: sprite set ccc to choose(-1,1)
sprite set angle to sprite.angle+sprite.ccc*sprite.speed
sprite set position to x = 250+cos(sprite.angle)*distance(sprite.x,sprite.y,250,250) and y = 250+sin(sprite.angle)*distance(sprite.x,sprite.y,250,250)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat Nov 09, 2013 8:24 am

@ash1221 I made this example capx
I made the same speed for all of them, but you can make an instance variable holding the speed, and made it generate randomly.
This is what I did:
1. set a boolean instance variable to know if the sprite is rotating or need a new updated direction and nr of rotations.
2. set and substract/add from instance variable the amount of degree to be rotating. (1800 means rotate 5 times to the left, 1800 rotate 5 times to the right ).
3. if instance variable representing the amount of degree has pass the zero than request a new rotation
B
81
S
21
G
23
Posts: 515
Reputation: 18,702

Post » Sat Nov 09, 2013 12:52 pm

thanks guys, i figured out how to do it now
B
20
S
8
G
2
Posts: 122
Reputation: 3,202


Return to How do I....?

Who is online

Users browsing this forum: adventurist, Blendi1223, PROxMTswatTR, ST314, Yahoo [Bot] and 35 guests