- Home /
What is the best method to use to ensure perfect collision detection on moving bodies?
I have a space game heare where my main character is a fast moving space ship.
I have many objects in my scene which my space ship should be able to crash into . I am using Occlusion culling on my camera so allowing the ship to even barely pass through any object is not an option.
My parent child relationship of my ship looks like this
▼ShipBody
Mesh
My ship currently passes through my objects even though i have placed a mesh collider on Mesh and a Rigidbody on ShipBody.
you can disregard what I have said but i would just like to know the best war to ensure continuous perfect collision detection.
First obvious question would be: Have you put a collider and Rigidbody on the objects you want to collide with as well?
Also to ensure better continuous collision detection you can go into the ships (and objects) rigidbody and change the "Collision Detection" property to "Continuous Dynamic".
Are you by the way moving your ship using force and velocity in rigidbody or translating it with transform?
yup I added rigidbodies to the objects to be collided with.
I have tried setting the collision detection to continuous dynamic but i get the same result.
I am moving the ship using Transform.
Reducing the fixedTimestep seems to have the biggest impact on mitigating this problem: Edit > Project Settings > Time. Try reducing the fixedTimestep from 0.02 to 0.01 to start. The smaller the number, the better the detection, but at the cost of CPU cycles. You might also take a look at this script:
When moving the ship using the transform you are in reality just teleporting it to a new position each frame. No physics calculations are done. You can try moving it with .ApplyForce or .$$anonymous$$ovePosition of rigidbody ins$$anonymous$$d. Or using the script that flaviusxvii provided belove.
well yeah in actuality i'm just moving the position of the ship over short intervals using Transform .If thats the cause , it is rather problematic . I will try the code flaviusxvii linked me to . if that still does not work I will revert to using ApplyForce.
Answer by flaviusxvii · Dec 02, 2013 at 07:53 PM
I have a space combat game that uses a slightly modified version of the script to ensure that weapons fire doesn't skip past stuff. It works great.
You must not have colliders set up properly. Were you fiddling with layers at all?
it works now but i had to attach a collider ,Rigidbody and the script to ShipBody and now i am unable to hit $$anonymous$$esh with a projectile unless i remove the rigidbody from ShipBody .
is there a way to work around this and keep both functionalists ?
I am not an expert, but I hear a lot that mesh colliders glitch a lot, I suggest putting one or many box colliders. Unity can prosses physics better with box colliders (Faster, more efficient, not to mention actualy collide)
that would be impossible with the current structure of my space ship . and also the codes i have require that i have just one collider.
Your answer
Follow this Question
Related Questions
Unity 5: No collision with other objects after an animation? 0 Answers
How to allow collisions on a Child of a Non Kinematic RigidBody ? 1 Answer
Unreliable collision detection between rigidbody and mesh collider 1 Answer
Accessing the rigidbody of a linerenderer via Script 0 Answers
Checking collisions between two objects that don't have rigidbodies 1 Answer