Using interpolation (lerp) on Angle

For questions about using Classic.

Post » Thu Feb 11, 2010 1:33 am

Hey everyone!
I'm starting a new project and i'm already stuck!

I'm trying to add the linear interpolation on a sprite's angle, but I may have to make a workaround for it to work as I wanted.

You see, the problem appears because you have angles from 0 to 359 degrees. Once you make the whole circle, it goes from 359 to 0 again. But since the interpolation uses the angle to calculate the distance, once you reach 359 them go to 0, the sprite will go back from where it came, making a really bad movement :cry:

What would be the best way to solve this? I'm trying to make variable that is always adding or subtracting the angles, so instead of 45 on the second turn I'd have 360 + 45, but still didn't manage to do it (working on it as I post this).

Here's a .cap for evaluation!
http://www.gamma-beam.com/construct/lerpangle.cap

On Adobe After Effects you have, on the angle controls, a counter that tells you how many turns it has done. It is displayed as "3 x 60". I don't know if that is a good thing for construct, but maybe knowing how many turns an object has performed would be a nice addition. I don't know, I'm just throwing things here :P

Thanks in advance!
Gammabeam
B
106
S
40
G
10
Posts: 456
Reputation: 13,152

Post » Thu Feb 11, 2010 2:14 am

the System object has an Angle difference expression that always works correctly. You could use that.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Thu Feb 11, 2010 2:38 am

That's very nice, Madster. No matter how much I look at the system expression, I'm always learning new stuff!

However, the output of the angle is still between 0 and 360, so it didn't seem to work. :(
B
106
S
40
G
10
Posts: 456
Reputation: 13,152

Post » Thu Feb 11, 2010 5:21 pm

Well, this is a bit too buggy than I'd like it to be, but here it is anyway. I hope someone more skillful at Construct would fix it.
B
4
G
4
Posts: 65
Reputation: 1,305

Post » Thu Feb 11, 2010 5:49 pm

If it works for sprite 2, then it will also work for sprite, just use the "Rotate towards position" expression, it allows for an amount of degrees you can use. You can then vary the amount of degrees via lerp.
+ System: Always (every tick)
-> Sprite2: Set angle towards (MouseX, MouseY)
-> Sprite: Rotate lerp(1, 20, 1-0.5^timedelta) degrees toward (MouseX, MouseY)
-> Sprite2: Set position to object Sprite (image point 0)
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Thu Feb 11, 2010 6:23 pm

newt's solution is probably the best idea. I thought I'd made an Angle Lerp expression, but I wrote it for something else. Might be useful to add to the next build?
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Thu Feb 11, 2010 6:31 pm

Well, that was my first thought, but adding lerp to the rotation amount still doesn't make it right, because if you go through that 360-0 threshold the same thing will happen.
B
106
S
40
G
10
Posts: 456
Reputation: 13,152

Post » Thu Feb 11, 2010 6:59 pm

So you want it to keep track of the number of total degrees it's rotated since the start of the game? Like, it will return 1080 degrees if it's rotated three times?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Feb 11, 2010 9:10 pm

Hey gammabeam, you can get a smooth lerp-like effect this way without actually using lerp:
http://dl.dropbox.com/u/529356/lerpfish.cap

I hope this is the effect you were going for. The fish thing is rotating towards an image point on the arrow. And you can change the rate at which it follows the mouse by changing the *4 part of the equation to something else. Higher numbers will rotate faster.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Feb 11, 2010 9:21 pm

Touch, sir Deadeye! :D

That's it!
Damn, I never understood how timedelta can make accelerations... Thanks a lot!
B
106
S
40
G
10
Posts: 456
Reputation: 13,152

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest