collider Guides Tutorial

Prevent colliders from passing through each other.

Nabeel
August 11, 2016
4 Comments
Home
collider
Guides
Tutorial
Prevent colliders from passing through each other.
Prevent colliders from passing through each other.


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):


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.

Blog authors

4 comments

  1. Anonymous
    Anonymous
    July 7, 2014 at 12:14 PM
    lets call it "not practical" unless you will have very few number of objects.
  2. Anonymous
    Anonymous
    July 7, 2014 at 7:22 AM
    dummy solution, useless.
    1. Nabeel
      Nabeel
      July 7, 2014 at 8:51 AM
      how it is useless? describe me
  3. Programmer
    Programmer
    July 7, 2014 at 5:49 AM
    Are you mad setting the iteration count to 50?
    You need to consider performance too!