How do I move object toward X without them overlapping

Get help using Construct 2

Post » Wed Oct 21, 2015 3:47 am

I have a top down view game with a player and an enemy.
Enemy moves toward player using pathfinder but when it collides with the player, it stops.
At this point, i don't want the enemy to overlap on top of player object.

I've tried setting solid behavior on both objects but they still overlap.
I've tried giving them physics but then when the enemy collides with the player, it pushes it around when i don't want them to be able to push each around.

Thanks
B
5
S
1
Posts: 32
Reputation: 439

Post » Wed Oct 21, 2015 4:44 pm

Make the destination the AI goes to, NOT the destination sprites (player) center. Make the point they go to actually 16 or 32 units away from the actual sprite.

Find path to----> sprite.x-sprite.width. And sprite.Y-sprite.Height.

This will put it diagonal under the target sprite.

Hope I understood you correctly.

If you want an example send me a private message. I have AI, and Pieces of AI that might help you out.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Thu Oct 22, 2015 2:32 am

thank you for reply.
enemies can approach the player from any angle, so if i follow the approach i would have to create many points around the player.
i feel like there should be a better way to do this.

I want it to also handle the case where there are multiple enemies surrounding the player and i don't want any of them overlapping each other.
B
5
S
1
Posts: 32
Reputation: 439

Post » Thu Oct 22, 2015 6:37 am

@kimtaein1

set a variable "distance" to the enemy.

every tick: set enemy.distance = distance(player.x,player.y,self.x,self.y)

if enemy.distance > 100 --> path find...
B
70
S
24
G
9
Posts: 175
Reputation: 7,539

Post » Thu Oct 22, 2015 9:04 am

Can't you just add condition along the lines of

If player collides with target -------- player pathfinding movement STOP

?
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Thu Oct 22, 2015 9:34 am

Or

negate(enemy is overlapping player) --> path find
B
70
S
24
G
9
Posts: 175
Reputation: 7,539

Post » Thu Oct 22, 2015 9:41 am

There is some built in NO-overlap things with the 8-direction and platform behaviors IIRC. Just add the behavior, and see if they still overlap. I think they will try to push away from each other by default.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Thu Oct 22, 2015 11:18 am

https://goo.gl/e6hRts (r215)

using on collision stop the path movement.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 4 guests