How do I make smooth, clock rotating object using "physics"

0 favourites
  • 5 posts
From the Asset Store
Simple resize and rotate events for any sprite, quick and easy event sheet that you can use for your own projects.
  • Hey guys.

    I have problem how to make controlled, rotating object by using physics (and apply torque for exampe) ?

    I want to make behavior like: When i click the object > this object should rotate toward 90 degrees from his previous angle and than stop rotating (stops everytime when reached next 90 degrees for example) until next "click/touch" on this object will happend. And but i want to make that on physics because I have idea on logic game with physics elements with gravity etc..

    I tried something like that:

    1. On left mouse click > apply torque 10000*dt

    2. When the object angle = 90/0/180/270 --> set torque to 0

    I know, that maybe its not perfect idea so the 'behavior' wasn't perfect - the object sometimes stopped when is reached these angles, but usually it missed them..

    I tried that with behavior "rotate" but its isnt precise too...

    I tried another way - with anglelerp and another object, which was just a determinant of angles for the right object.

    So the objectX (the invisible determinant) had action like: when click left mouse on object > set angle: objectX.Angle + 90 degrees . And the second object with physics smoothly followed by the objectX by anglelerp. So it worked perfect - everytime it stopped when reaches 0,90,180 or 270 angle of direction - but than there was many problems with physics behavior.. and collisions on other objects. For example - my rotating object is a square and it has a hole (shape of the hole is square too for example) (without polygon collision zone in the hole place) inside, near one of corner. And in that hole there is another object - round ball for exmpl. with physics , gravity etc.

    And when i was turining the Square object by using the objectX target - many times the ball sprang out of the square..

    I don't know if this is understanding what i wrote but i tried. I can't show my example because of low amount of reputation points.

    So anyone have solutions for that ?

  • I think you got the right idea at the beginning. Just a few (minor) changes:

    global variable Clockquarter =1

    On mouse click -> apply torque

    if object.angle > (90 * Clockquarter) -> Clock set torque to 0

    Add 1 to Clockquarter

    if Clockquarter > 5 -> Set Clockquarter to 1

    We only write one comparison by multiplying 90 times the variable Clockquarter (which changes from 1 to 4) , the first time will compare to 90, the second time to 180 ( 90 * 2 ) and so on. If Clockquarter is larger than 4 (that means the clock did a full revolution), we set it to 1 again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey makotto.

    I tried that, and it doesn't work.. probably i made something wrong. Thats how i made that:

    Global number ClockQuarter = 1

    1.On left button Clicked -> Sprite1: Apply Physics torque 1000000*dt

    2.Sprite1: Within 0 degrees of Sprite1.Angle > (90 * Clockquarter) -> Sprite1: Apply Physics torque 0 / add 1 to ClockQuarter value

    3.ClockQuarter < 5 -> Set ClockQuarter to 1

    Can you send me example, or explain what i've done wrong?

  • Okay, this is the way I would do it (no physics):

    https://www.dropbox.com/s/76ceo0sm6pbsnfb/clock%20no%20physics.capx?dl=0

    You can change the rotation speed in the rotationSpeed variable. Please note that the faster it spins, the more you will have to adjust the bounds for the last part of the revolution ( 358 < Sprite.angle < 359.9)

    Let me know if it helps.

  • Thank you very much

    I think thats it! It works pretty nice and there is no problems (at this moment) with physics.

    Thanks again

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