How do I Get A Sprite To Run Away From Player?

Get help using Construct 2

Post » Sun Apr 20, 2014 2:56 pm

How do I Get A Sprite To Run Away From Player? I have a player and I want it so when the player gets near the sprite the sprite will move away from the player. How to do this? Help is greatly appreciated :)
B
37
S
14
G
3
Posts: 263
Reputation: 4,270

Post » Sun Apr 20, 2014 8:56 pm

Have you tried the Line of sight behavior? This is an example tutorial https://www.scirra.com/tutorials/474/pa ... e-of-sight
B
10
S
3
G
1
Posts: 16
Reputation: 776

Post » Sun Apr 20, 2014 10:01 pm

Are you talking about top-down movement? Side-scrolling Platform?

Anyway, you can either create an invisible sprite that covers the area that you want the enemy to be alerted with and pin it to the player, or compare the distance between the Player and the Enemy and when it's below a threshold trigger the moving away action.

If you can be more specific it will be easier to help you.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Apr 21, 2014 1:28 am

@eli0s Sorry I meant a side scrolling.
B
37
S
14
G
3
Posts: 263
Reputation: 4,270

Post » Mon Apr 21, 2014 2:59 am

Ok, since I don't know which method will prove more useful, in this example capx I move to enemies away with the platform behavior (when the ground is uneven) and on just the x axies if the enemy doesn't heve to follow any ground changes...

http://www.eli0s.com/Tests/RunningAwayEnemies.capx

Tell me if it's close enough.
Last edited by eli0s on Mon Apr 21, 2014 11:36 am, edited 1 time in total.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Apr 21, 2014 3:15 am

@eli0s Your method is great but my enemy is not on a solid object and is not a platform. Neither is my player so is there anyway to use both X and Y axis to move anywhere on the layout.
B
37
S
14
G
3
Posts: 263
Reputation: 4,270

Post » Mon Apr 21, 2014 11:36 am

Yes, of coarse, the second method is the one you'll have to use, just add move at an angle (angle(Player.X, Player.Y, Enemy.X, Enemy.Y)) to drive the enemies away.

Simple way http://www.eli0s.com/Tests/RunningAwayEnemiesSimple.capx

A bit more advanced using Physics http://www.eli0s.com/Tests/RunningAwayEnemiesPhysics.capx
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Apr 21, 2014 2:40 pm

Thank you @eli0s. You've been a great help!!!
B
37
S
14
G
3
Posts: 263
Reputation: 4,270

Post » Mon Apr 21, 2014 3:12 pm

You're welcome! ;)
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 36 guests