Avoiding your objects from passing with each other is really tricky especially for fast moving objects like bullets and Prevent colliders.
Today we made tutorial and script for you to show how to prevent colliders from passing through each other.
The best way to make sure that you detect all collision is to use Raycasting instead of depending on the physics simulation. This is helpful for bullets or small objects, but will likely not provide great results for large objects.
Below answer is from stackoverflow
Collision with fast-moving objects is always a problem. A good way to
ensure that you detect all collision is to use Raycasting instead of
relying on the physics simulation. This works well for bullets or small
objects, but will not produce good results for large objects.
http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html
Pseudo-codeish (I don't have code-completion here and a poor memory):
Pseudo-codeish (I don't have code-completion here and a poor memory):
void FixedUpdate()
{
Vector3 direction = new Vector3(transform.position - lastPosition);
Ray ray = new Ray(lastPosition, direction);
RaycastHit hit;
if (Physics.Raycast(ray, hit, direction.magnitude))
{
// Do something if hit
}
this.lastPosition = transform.position;
}
see also: Concave collider
If you like and never wants to miss our articles then just subscribe us,
And join our Facebook group with Lots of great developers.
Are you mad setting the iteration count to 50?
ReplyDeleteYou need to consider performance too!
dummy solution, useless.
ReplyDeletehow it is useless? describe me
Deletelets call it "not practical" unless you will have very few number of objects.
ReplyDelete