Search Unity

CollisionFlags without character controller

Discussion in 'Scripting' started by Rhuantavan, Jun 21, 2006.

  1. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    I am making a platformish game and I want to make it from scratch, so I don't want to use the character controller - also because the character needs to be heavily affected by physics. I am using a capsule collider. Is there a way to calculate where the collision took place (head, sides, legs)? How is it done in the character controller? Thanks!
     
  2. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Yes, you can tell the 3D coordinate that was hit. From the manual under Collision (script alphabetic reference), with contact being a variable of your choosing:

    Code (csharp):
    1. for (var contact : ConactPoint in collision.contacts) {
    2.         print(contact.thisCollider.name + " hit " + contact.otherCollider.name);
    3.         // Visualize the contact point
    4.         Debug.DrawRay(contact.point, contact.normal, Color.white);
    5.     }
    You can use contact.point to get the coordinates that were hit. I think that's in world space so you might have to use transform.InverseTransformPoint(contact.point) to get the local coords.

    Then you can evaluate the point to decide where it was hit. Below a certain y might be legs, for instance.

    You could also have multiple colliders, one for each leg, etc.
     
  3. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    Thanks a lot Morgan, I haven't noticed that entry in the manual. I'll try this and see what I can make out of it.