- Home /
Enemy rigidbody and bullet collisions
Hello, as the title suggests, the enemies in my game have rigidbodies attached.
Firing a bullet against enemies make them spin and bounce away (obviously, it's a space game and there's no drag at all) but I'd like to avoid that behaviour. I can't set enemies to Kinematic because, as I said, I need forces to have effect on them, but at the same time I don't want them to bounce away after a bullet collision.
How can I avoid or at least minimize that effect?
I was thinking to set them to Kinematic just when collision happens, then immediately switch back to non kinematic, but I'm not sure of the final result... In that short (1 frame) moment, every force would stop having effects on the enemy, movement included, and I guess it would be bad.
Thanks in advance for your help. Have a nice sunday.
Answer by DanielGL · Jan 24, 2021 at 03:28 AM
I thought in two solutions:
1-You can make the collider of your bullet a trigger, if you need a physic collider in your bullet for some reason you will need to use layer masks to make the Enemy only receive the trigger collider. 2-You can save the current velocity value of your enemies every frame, so when they get hited you apply the value on them, something like this:
Vector2 currentVel;
if(hited == false)currentVel = rb.velocity;
else rb.velocity = currentVel;
Oh, right, the trigger approach is the answer. Thank you very much. :)
Your answer
Follow this Question
Related Questions
Enemy death help 1 Answer
isKinematic object doesnt collide with wall 3 Answers
Collision Detection for Kinematic Rigidbodies 0 Answers