0 Favourites

Rotating a layer

  • 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 anglelerp ! Maybe ?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
feature request: layer offset
45 2,493
lennaert's avatar
lennaert
Unread hot topic
43 2,266
Zebbi's avatar
Zebbi
Unread hot topic
43 4,539
newt's avatar
newt