How do I stop sprites overlapping

Get help using Construct 2

Post » Mon Jun 16, 2014 8:12 am

I came across a problem that when I have two enemy sprites following my character they overlap . I want to figure out how to make them not overlap but still follow the position of the character. It would make my day if somone helped me with this and posted the code in the replies. Thanks!! :)
B
8
S
3
G
2
Posts: 53
Reputation: 1,764

Post » Mon Jun 16, 2014 9:11 am

Have you tried making them solids?
(\__/)

(='.'=)

(")_(")
B
23
S
10
G
1
Posts: 74
Reputation: 3,244

Post » Tue Jun 17, 2014 5:35 pm

As thenormalgeek said: "Solid" behaviour. Right click > behaviours > solid
B
33
S
5
G
1
Posts: 163
Reputation: 2,693

Post » Wed Jun 18, 2014 8:48 am

Does this work with Custom Movement? And is the way it pushes out of solids still kinda glitchy? I really need a good, dependable 'mob' behaviour for a top-down shooter, where enemies will chase the player, surround him if they catch him (rather than all clumping up on the same space) and not clip through solid objects and glitch around while they're doing it. If anyone could point me to someone who's achieved an AI like this I'd be very grateful :D
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Wed Jun 18, 2014 8:52 am

put an invisible barrier around enemy.
Last edited by DUTOIT on Wed Jun 18, 2014 9:02 am, edited 2 times in total.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Jun 18, 2014 8:56 am

That sounds... hi-tech :)

Would you mind telling me a bit more @DUTOIT? AI is one of those areas where I suck seriously hard, I find it really frustrating.
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Wed Jun 18, 2014 9:05 am

I think what he means is pinning an invisible sprite to every enemy, and making that sprite have a bigger hitbox than the actual enemy sprite (the area which you don't want other enemies to enter). You should also place it in a container with the enemy. Then, whenever those sprites collide with something, you can do whatever your logic determines (such as making the enemies go away from each other and then continue to pursue the player), or if you want the easy way out you just give the invisible sprite the solid behavior.

This way you achieve enemies never clipping with each other without actually having to affect their hitbox (which I assume you want unchanged for shooting them or whatever way you have of damaging/defeating them)
B
6
S
2
Posts: 79
Reputation: 608

Post » Wed Jun 18, 2014 9:09 am

monitz87 wrote:I think what he means is pinning an invisible sprite to every enemy, and making that sprite have a bigger hitbox than the actual enemy sprite (the area which you don't want other enemies to enter). You should also place it in a container with the enemy. Then, whenever those sprites collide with something, you can do whatever your logic determines (such as making the enemies go away from each other and then continue to pursue the player), or if you want the easy way out you just give the invisible sprite the solid behavior.

This way you achieve enemies never clipping with each other without actually having to affect their hitbox (which I assume you want unchanged for shooting them or whatever way you have of damaging/defeating them)


Exactly.
If you are a sucker for punishment you can also run a few checks when enemy 10px from hero do this that etc
But I would go the clear sprite / add container / pin it or set collision polygon wider than enemy and turn on solid behavior.
But the clear sprite and collision gives you greater options with AI.

Sidenote: I suck at AI too... lol

I accidently hit back button and wiped my comment above. I said something like force field/invisible barrier, couldn't remember in case you wonder why I edited it ;)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Wed Jun 18, 2014 9:36 am

Cool, I'll have a play around with that later. Does the invisible sprite also need to have the main movement routines (eg I'm currently using MoveTo + Line of Sight to chase the player when they can see him), or can you assign those to the main sprite, and just leave the pinned invisible ones as Custom Movement with Solid enabled and it'll work itself out?

My main problem in the past has been the way sprites sort of 'pop' around the place when pushing out of solids, especially when clumped - it just looks glitchy and bad. A lot of my game is also in very tight tunnels which makes it doubly hard to find something that works.
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Wed Jun 18, 2014 9:41 am

lolpaca wrote:Cool, I'll have a play around with that later. Does the invisible sprite also need to have the main movement routines (eg I'm currently using MoveTo + Line of Sight to chase the player when they can see him), or can you assign those to the main sprite, and just leave the pinned invisible ones as Custom Movement with Solid enabled and it'll work itself out?

My main problem in the past has been the way sprites sort of 'pop' around the place when pushing out of solids, especially when clumped - it just looks glitchy and bad. A lot of my game is also in very tight tunnels which makes it doubly hard to find something that works.


As far as I know, you just have to pin the invisible sprite to your enemy sprite, you don't even have to use custom movement on it, it will just follow the enemy sprite around. But as DUTOIT suggested I'd rather not use the solid behavior and set the AI myself whenever the invisible sprites collide. That's doubly true if you're gonna have tunnels in your game, because if you set the force fields to solid, then the enemies might not fit into the tunnels, or bounce around a lot when they're traversing them. Also I'm not sure how it would work out if both your enemy sprite and the invisible one are solid.
B
6
S
2
Posts: 79
Reputation: 608

Next

Return to How do I....?

Who is online

Users browsing this forum: ametueraspirant, dand, mickclarke and 35 guests