the NPCs in my game like Guards, Civilians and enemies keep bumping and bouncing into eachother can somone help me fix this problem without it effecting how they interact with walls and other solid objects ?
if possible id like the enemies and guards to lock on to each other in combat and face each other same for the enemies and player .
Hey @probablydon - first of all, and this is completely unrelated, but I finally played through Thrall the other day, and I was blown away. Absolutely fantastic work on that game.
Anyway, regarding this new game it sounds like you’re asking about three distinct issues, so I want to clarify:
- You’re looking for a way to skip collisions only between certain objects
- You’re looking for a way to have the NPC “lock on” to each each other, which I assume means once they get withing a certain distance, they try to stay together
- Your looking for a way to have the NPCs face the target they are attacking (either each other or the player)
Does all that sound correct?
i always wondered if you played it yet, thank you means alot.
i dont want my NPCs to walk over or through eachother, i just dont want them to bounce eachother out of the way into walls and other solid objects.
the player sprite always pushes others all over the place, ive tried messing with the gravity and ive tried setting there velocities to zero when collision occurs but it isnt working.
when my guards fight the enemies and vise versa they dont even look at eachother and sometimes are attacking backwards lol.
you kind of have the right idea
From a high-level, I see two potential approaches to improve the NPC movement.
One approach could be to make the NPC movement AI more sophisticated. You could take an approach maybe something like Boids where each NPC moves along with but avoids his neighbors. This sounds like it could be tricky to get right, but might be a path towards some pretty interesting emergent behavior.
Another approach could be to change the NPCs to be kinematic objects. Meaning they are solid objects that can move around, and other things can collide with them, but they are not affected by physical forces. With this approach, they cannot push each other around. If you make them solid, but uncheck the “movable” checkbox, then they will become kinematic objects.
This will present a new problem, however. If they are being manually moved around, then you will have to handle the collision detection manually. One approach could just be to cast a short ray in front of the NPC, and only move forward if the ray doesn’t hit anything. If you do this, you’ll need to be careful not to send too many raycasts per frame or it can impact performance (maybe use a timer, or an InView check?)
i think the ray casting is a really good option ill have to play with it cause im not very experienced with rays. ill try unmarking the moveable checkbox and mess with it , thanks Grazer.
Either not solid or kinematic, I think using a short raycast, x and y, filters, and position is the best option.
For example, if it detects a wall on the right. Make it not go greater than its current X position.
does the shape have any thing to do with it or does it not matter ?
I’m not sure exactly what you mean - the shape will affect the collision area, and some shapes are more efficient than others. I would probably use rects, unless you need to use something else specifically.
im messing with it now, i changed their shapes to recs and added a ray that tells the NPC when it touches the solid top or bottom of a wall, it sends the NPC to an alternate route ( stairs ) so instead of the guards and invaders having a weird stare down when divided by a wall, they will use the stairs to chase eachother. seems to be working good . . . so far lol
and when attacking , their velocity is at zero now which draws back alot of the bouncing around and still gives them a little personality