Enemies pass through each other

Ok, I’ve researched a bit, tried a few things, but I’m stumped. I can’t get my Enemies to stop passing through each other. For context, it’s important to know in my game (and I’ve attached a screen shot), I’ve turned spaceships in Space, to cars on a highway. And I also spawn waves in parallel (makes more sense in the Highway case). So for cars on a highway, I can’t have them go through each other.

I already did some research, and saw the colliders wouldn’t work to keep them from going through if they had a trigger. So I tried a suggested trick to add a 2nd collider inside the first one, without the trigger. That did not work.

Then for testing I removed the trigger altogether (from both). That still doesn’t work. So I’m stumped.

I’m attaching screenshots of the game showing the problem, and of my Enemy collider and rigid body. Any help would be appreciated.

Game:

Collider:
box_collider

Rigid Body:

So for Rigidbodies and collision I’d recommend you look at the Unity. Documentation. It can be kind of confusing.
I’d try setting the body type to something that isn’t Kinematic. If I’m remembering right a Kinematic rigidbody won’t register collision with a collider.

If this fails you could always look into making your own custom collision with raycasts. Basically projecting an invisible line a certain distance away from your car in each direction. Up,Down,Left, and Right and if the line hits something stopping the car from moving.

Thanks much for the reply. Kinematic should work, since we used that in the Block Breaker game. And it does register a collision, because when I have the trigger on, I get the callback without a problem.

Raycasts are “above my paygrade” at the moment. But I guess it wouldn’t be the first thing I have to go off script an learn ahead. Thanks for that tip.

But in anycase, the fact that the plain collider solution is not working still bothers me. Seems like plain functionality that should work.

Ok … so changing rigidbody from Kinematic to Dynamic made it work. Strange, because I know I had collision on my Block Breaker kinematic moving barriers (I double checked). So I’d still like to understand why.

But with the change, it’s actually better than I expected. I figured they would just bounce, but when the cars hit, they swerve. Very realistic. I even had some “highway pileups”. Cool.

From the manual:

A Kinematic Rigidbody 2D does not collide with other Kinematic Rigidbody 2Ds or with Static Rigidbody 2Ds; it only collides with Dynamic Rigidbody 2Ds

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms