Slide sprite at angle relative to current position

Get help using Construct 2

Post » Fri Sep 13, 2013 2:06 am

In my top down shooter when my player sprite collides with my enemy sprite, I want the enemy sprite to smoothly move/slide 500 pixels away from my player sprite (relative to the enemy's current position). The speed of movement would depend on the enemy type.

Looking at similar posts I think I need to use lerp but not sure how this would incorporate both x and y movement and the angle of movement. Would it require separate actions?

Any suggestions appreciated.
B
5
S
1
Posts: 44
Reputation: 665

Post » Fri Sep 13, 2013 3:56 am

I think this would work (Image here):

Add these instance variables to the enemy:
"timer" starts at 100
"playerX" and "playerY" starts at 0

Events:

Enemy collision with player
> Enemy set "timer" to 0
> Enemy set "playerX" to 0
> Enemy set "playerY" to 0

Enemy "timer" < 100
> Enemy set "timer" to clamp(timer+(10*60*dt),0,100)
> Enemy set X to
self.x + (cos(angle(self.x, self.y, self.playerX, self.playerY) ) *-1* lerp(0, 30, self.timer*0.01))
> Enemy set Y to
self.y + (sin(angle(self.x, self.y, self.playerX, self.playerY) ) *-1* lerp(0, 30, self.timer*0.01))

10 is the speed at which it moves.
30 is the distance
7Soul2013-09-13 03:57:29
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Fri Sep 13, 2013 9:40 pm

Have tried this out but the movement doesn't seem to be right. I'm aiming for "soccer ball" type movement when the enemy is kicked by the player.

Have created an example: https://copy.com/BlfuSTiwuoqy
B
5
S
1
Posts: 44
Reputation: 665

Post » Fri Sep 13, 2013 10:05 pm

Here's an alternative with Bullet and Timer.
EnemyHitTest_BHT.capx
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Fri Sep 13, 2013 11:01 pm

That seems to work fine, thanks.
Is there any way to get the enemy to slow to a stop rather than immediately stop? Have tried setting gravity to a negative value before the timer action but this doesn't seem to work.
B
5
S
1
Posts: 44
Reputation: 665

Post » Fri Sep 13, 2013 11:04 pm

Set the Acceleration to a negative value. You'll need to play with the numbers.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Unconnected, Waltuo and 18 guests