Lerp at Angle

0 favourites
  • 7 posts
  • I'm trying to figure out a way to lerp an object in the opposite direction of the player a couple hundred pixels, but can't seem to figure out if it's possible.

    Currently I've created instance variables on the lerping sprite as SpriteX & SpriteY, and also an AngleToPlayer isntance variable as angle(Player.X, Player.Y, Sprite.X, Sprite.Y), but I can't figure out how to set the spritex & y instance variables -/+ 200 pixels based on the characters position.

    In lamen's terms, I'm trying to make it so when you kill an enemy, a coin spawns on them and slowly moves away from your current position stopping in 100-200 pixels.

    Any help would be greatly appreciated.

    Thanks!

  • would "set angle to player+180 degrees not work?....

    With maybe a fade behaviour added,destroy after fade

    Or an animation that once ended destroy?

    Or bullet when distance travelled...

  • It would, but I want to do it with the lerp effect so as it moves away, it progressively gets slower.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add targetx and targety variables which you set at coin creation to point to desired target coordinate. Then each tick set position lerp(coin.x, coin.targetx, dt) . Same for y coordinate.

  • Hey Vee,

    That's how I'm trying to do it currently, but I'm having trouble figuring out how to calculate Coin.TargetX & Coin.TargetY.

  • Fortunately, I figured out a different way to do it using the Bullet behavior.

    I set an event "If Bullet speed > 0, change speed to Sprite.Bullet.Speed-5 every tick" to create a fake "lerp" effect.

    I am still curious if there is a proper math equation to calculate Coin.TargetX & Coin.TargetY based on the angle between the object and you if anyone knows of one.

  • I am still curious if there is a proper math equation to calculate Coin.TargetX & Coin.TargetY based on the angle between the object and you if anyone knows of one.

    Sure, just google up Pythagoras. It forms a triangle which you can use to calculate the X, Y if you know the angle and distance.

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