How to find the point of contact with the function OnTriggerEnter???

Hi,

(sorry for my bad english!)

I'm building a little train game. I have some wagons and a locomotive all on differents positions on the track (not touching each other). When I get the locomotive to touch a wagon, my script (who is attach to the wagon) create (AddComponent) a hinge and attach the hiting object (the locomotive or another wagon) to connectedBody of the hinge. This is working fine. My problem is I need to know where the trigger enter so I can move the anchor of the hinge to the front or the back of the wagon to get realistic movements. (Am I clear???)

Here the code:

var connected : boolean = false;

function OnTriggerEnter (other : Collider) {

if (other.gameObject.tag == "Wagon") {
    if (!connected) {
        var otherBody = other.gameObject.rigidbody; 
        gameObject.AddComponent (HingeJoint);
        hingeJoint.connectedBody = otherBody;
        hingeJoint.axis.y = 1;
        hingeJoint.axis.x = 0;
        // move the anchor of the hinge to the pont of conctact (HELP!!!)
        connected = true;
    }
}

}

Thank you very much for your time and your knowledge!

Maybe you can try using this

other.gameObject.GetComponent<Collider>().ClosestPointOnBounds(transform.position);

OnTriggerEnter() does not handle collision information, just detects if there was a collision. So you cannot find the point of collision like you would with OnCollisionEnter().

You could however turn off isTrigger and add a rigidbody component to the object with the collider that you are running OnTriggerEnter() on, and make it a kinematic rigidbody, though. Then it would function just like a trigger, but you could use the collision information in OnCollisionEnter() and get the contact point.

Once you have that, you can get the contact point with OnCollisionEnter like this:

function OnCollisionEnter(collision : Collision){
    var contact : ContactPoint = collision.contacts[0];
        contact.point; //this is the Vector3 position of the point of contact
}

Also, your English is pretty good. :)

Hi, you can try that, is simple and fast for detect collision coordinate:

function OnTriggerEnter (other : Collider) 
{ 
  print(other.transform.position);  
}

G.B

i am stuck a bit here. i am not using any rigidbody in my object here. but still i want to find the reflect of the point where my ball collides. How can i get that outside the OnCollisionfunction? is that even possible? Both the ball and my wall has colliders bu t none of them have rigidbodiy. But still i want a reflecting vector.