How do I stop my sprites from overapping

Just started using Construct 2? Post your questions here

Post » Thu Mar 31, 2016 9:10 pm

it works with the pillars, but not with enemies who eventually bunch up on one another.

https://drive.google.com/file/d/0B3UaHQ ... sp=sharing
B
7
S
2
G
1
Posts: 10
Reputation: 997

Post » Fri Apr 01, 2016 4:35 am

Hey J,

It's a lot harder than it might seem at first. It is a bit of work but you want to look into pathfinding (either using the behaviour or looking into how you would code it up yourself). Basically if you sort your map into little squares then it is less of an impact checking for collisions.

There are little things you can do to work around it but if you are going to have a lot of enemies on screen at once it's a worthwhile investment for your time. Trust me.
ImageImage
B
118
S
23
G
7
Posts: 1,070
Reputation: 12,964

Post » Fri Apr 01, 2016 11:15 pm

Here is a solution but it is not perfect.

Add to Sprite10 the instance variable (Overlap = 0)

Then :
Image

If two Sprite10 overlap each other, the furthest to Sprite6 will set his overlap variable to 1.
If the overlap variable is 1, the Sprite10 stop his pathfinding, wait 0.1s then "reset" his overlap variable.

I tried with 5 instances of Sprite10 and it works, you can manage the Z position of Sprite10 in the layer for better results.
B
12
S
7
G
4
Posts: 114
Reputation: 3,067

Post » Thu Apr 07, 2016 1:54 pm

thanks again man! didn't have a computer for a few days, just tried this and it does the job.
B
7
S
2
G
1
Posts: 10
Reputation: 997

Post » Fri Apr 08, 2016 3:07 am

The custom movement behavior also has a "push out solids" action that some people have found useful for preventing overlap in pathfinding situations like this.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Apr 14, 2016 3:56 pm

There's also a "push out solids" behavour that rex rainbow made that you can just add to your object, and they won't overlap.
B
87
S
44
G
16
Posts: 1,002
Reputation: 17,932


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests