- Home /
How to get contact point of collision.
Making an atari breakout kind of game. The further away from the centre of the paddle the ball hits the more angle I want it to bounce off at.
Thanks.
Answer by samf1111 · Sep 02, 2020 at 01:48 PM
Vector3 globalPositionOfContact = collision.contacts[0].point;
Answer by Harinezumi · Jul 30, 2018 at 11:18 AM
The documentation for OnCollisionEnter() gives a pretty good example: the contactPoints
member of the Collision
parameter gives you an array of contact points.
It looks like it gives the user where in space, not on the object, the collision happened. At least that's the results I'm getting.
Yes, it gives world space coordinates, which can usually be used for any purpose. What do you mean by "on the object"? If you want position relative to the object, you can use transform.InverseTransformPoint()
(scripting documentation).
Answer by Destanci · Jul 30, 2018 at 11:18 AM
private void OnCollisionExit(Collision collision)
{
Debug.Log(collision.contacts.Lenght);
}
collision.contact will return you a Array with ContactPoint s Where 2 Colliders Hits At. Research ContactPoint class at Unity docs will help you.
In the docs it said to avoid using this... eh.. whatever
I've just looked at the scripting reference and I can't find any mention about avoiding using this. Where did you see this? $$anonymous$$aybe it was trying to avoid using it many times during a frame?
just for clarification, the docs disencourage using the contacts property directly to avoid potential memory issues, as opposed to using the method GetContacts()
Answer by tormentoarmagedoom · Jul 30, 2018 at 11:32 AM
Come on... think about how to do it (not how the code is), but what you need to know, what you need to compare, and look at google or unity how to get that values...
Just saw this. You assume I didn't do these things. Is this how you normally "help" people?