- Home /
Find Contact Point on touch
Hello, I know how to find Contact point of collider when object collides with other object using OnCollisionEnter2D(Collision2D other) method.
but suppose i touch on some object, how can i get the contact point on touch?
Answer by CodeMasterMike · Sep 08, 2014 at 08:01 AM
Every collision has a array of contact points. Each contact point has a position where the collision occured. So you need to get those contact points in order to get the collision position.
void OnCollisionEnter(Collision collision)
{
for(int i = 0; i < collision.contacts.Length; ++i)
{
ContactPoint contact = collision.contacts[i];
Debug.Log(contact.point);
}
}
Collision points: http://docs.unity3d.com/ScriptReference/ContactPoint.html
thanks for your reply. I know this method.
but my question is that, suppose i touch on that object using raycast...howw can i get the point that where i have touched?
Do you mean where the ray is touching the object? If so, look at http://docs.unity3d.com/ScriptReference/RaycastHit.html where the point variable is where the ray touches the object. Otherwise the contact point(s) are exactly where there is a collision.
If you want the screen position where your finger touches, then you need to get the touch position from the touch input.
yes exactly, I got the points where my ray is touching the object.
Your answer
Follow this Question
Related Questions
Click Position 1 Answer
Touch Delay 1 Answer
Angry birds style zoom effect 1 Answer
GuiTexture touch button problem 0 Answers
i need a script to make object be destoryed after touching another 1 Answer