help in randomized rotation

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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.

  • 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.

  • 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)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • thanks guys, i figured out how to do it now

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