Lerp at Angle

Get help using Construct 2

Post » Wed Mar 20, 2013 7:51 am

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!
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Wed Mar 20, 2013 9:24 am

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...
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Wed Mar 20, 2013 5:27 pm

It would, but I want to do it with the lerp effect so as it moves away, it progressively gets slower.
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Wed Mar 20, 2013 5:42 pm

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.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Mar 20, 2013 5:52 pm

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.
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Thu Mar 21, 2013 6:52 am

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.
B
22
S
3
Posts: 451
Reputation: 2,135

Post » Thu Mar 21, 2013 7:38 am

[QUOTE=ome6a1717]
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.[/QUOTE]

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.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: Colorfish, Waltuo and 4 guests