How do I make sprites Avoid Player

Get help using Construct 2

Post » Thu Feb 28, 2013 4:14 am

I'm working on a chase game and I'm having a hard time getting my target sprite (the chased) to move away from the player sprite (chaser). Another problem I've been having is when I have the sprite cornered and I get close to it, it has a habit of shooting off to another corner. Truth be told I'm just having a hard time in general getting the behavior of the chased down... Ever attempt it gets faster as the chaser gets closer, while evil, would defeat the purpose of the game. Any help on how to make to make this work?datomsk6692013-02-28 04:23:49
B
2
Posts: 2
Reputation: 254

Post » Thu Feb 28, 2013 5:26 am

1. As distance gets less, make the chased move away. Hard to say why it's not working without knowing the details.

2. Maybe make the chased slow down the closer the chaser gets?

(see manual for "distance (x1,y1,x2,y2)")
B
7
Posts: 38
Reputation: 476

Post » Thu Feb 28, 2013 6:04 am

Alright. So that helped. I now got the distance variable working so it reacts and accelerates when the Chaser gets close.

System 0<distance(Chaser.X, Chaser.Y, Chased.X, Chased.Y)<500 Set bullet Acceleration to 500

How would I make it choose a direction. My current action is
Set Bullet angle of motion to random(random(Sprite.8Direction.MovingAngle+random(180))

But all it does is cause the Chased to spiral around and freak out... which of course means it's not getting very far.

I'll add more to slow it down when the distance widens. I imagine adding a path finding behavior will allow it to move around obstacles.

B
2
Posts: 2
Reputation: 254

Post » Thu Feb 28, 2013 6:41 am

@datomsk669

My first reaction would be to make it move directly away from the Chaser:

angle(Chaser.X, Chaser.Y, Chased.X, Chased.Y) + 180 (or -180, both lead to the same angle)
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Thu Feb 28, 2013 9:41 am

To get slightly more interesting/realistic behaviour, you might want to read up on Craig Reynolds' "Autonomous Steering Behaviours" - http://www.red3d.com/cwr/steer/

For this example, what you're describing is the "Flee" behaviour, which applies a steering force (an acceleration, if you prefer) in the opposite direction from the direction to the player. However, I strongly encourage you to read the other behaviours too.
B
8
S
2
G
3
Posts: 83
Reputation: 2,668


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 29 guests