Rotating a layer

Get help using Construct 2

Post » Mon Oct 29, 2012 4:50 pm

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).Kazan2012-10-29 16:50:56
B
13
S
6
G
5
Posts: 74
Reputation: 3,991

Post » Mon Oct 29, 2012 5:25 pm

try anglelerp ! Maybe ?
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Mon Oct 29, 2012 6:02 pm

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.keepee2012-10-29 18:04:49
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, NRABrazil, PixelatedTrip and 27 guests