Using interpolation (lerp) on Angle

This forum is currently in read-only mode.
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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

    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

    Thanks in advance!

    Gammabeam

  • the System object has an Angle difference expression that always works correctly. You could use that.

  • 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.

  • 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.

  • 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)

  • 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?

  • 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.

  • 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?

  • 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.

  • Touch�, sir Deadeye!

    That's it!

    Damn, I never understood how timedelta can make accelerations... Thanks a lot!

  • 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?

    You could add a "Rotate towards angle" function for sprites while you're at it. Right now you have to use a workaround like "Rotate towards position: Sprite.X+Cos(TargetAngle)*10, Sprite.y+Sin(TargetAngle)*10", which isn't really all that intuitive.

  • You could add a "Rotate towards angle" function for sprites while you're at it.

    Agreed, it would be nice. I've been caught more than once staring blankly at the angle actions and scratching my head in confusion before remembering it doesn't actually exist.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • set rotation to (sprite.angle + (angledifference(sprite.angle,desiredangle)*factor*timedelta))

    will rotate the sprite towards the angle you put in desiredangle at a rate of factor per second.

  • madster this just keeps turning clockwise what if one wants to go anticlockwise.

  • well that's an old post...

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