Rotating a layer

0 favourites
  • 3 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.
  • This is probably fairly basic but maybe I've been trying to do this for too long.

    I'm trying to do a simple effect really. When I left click with the mouse I want a specific layer to rotate smoothly to -30 degrees.

    Using lerp this is what I got:

    Set layer 0 angle to lerp(layerangle(0),-30,0.5*dt)

    Now that works...kinda, but when I click it only rotates in small increments, it doesn't completely rotate in one smooth motion to -30 degrees. I have to keep clicking repeatedly.

    Tried doing this with other layer effects as well like scale and position, same deal.

    Oddly enough, if I use an on mouse button down instead of just clicking it works fine (well, it repeats endlessly but it works).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • try anglelerp ! Maybe ?

  • What Whiteclaws said, but also it's only going in small increments because the event is only running for a single tick .. the tick of which you click the mouse button.

    What you'll need is another variable, call it "TargetAngle" or something

    +On click

         -> set TargetAngle to -30

    +Compare two values: LayerAngle(0) is not equal to TargetAngle

         +Compare two values: is anglediff(LayerAngle(0),TargetAngle) Greater than 1

                  ?->set LayerAngle(0) to Anglelerp(LayerAngle(0) , TargetAngle , dt*0.5)

         +Compare two values: is anglediff(LayerAngle(0) , TargetAngle) Less or equal to 1

                  ?->set LayerAngle(0) to TargetAngle

    The reason for the last event is so it stops the lerping once it's too close to really recognise the change.

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