- Home /
Question by
jonesid27 · Dec 15, 2014 at 09:29 AM ·
collision detectionlinecollision-detection
Draw Line on mouse move and detect line collision in Unity 2D and Unity 3D -
I used the code for line collison from http://www.theappguruz.com/tutorial/draw-line-mouse-move-detect-line-collision-unity2d-unity3d/ and it's working all right. It detects when line collides with itself,but I need to check collison with other objects(lets say a platform).I added this function in script:
private bool isLineCollidedWithOtherObject()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Camera.main.WorldToScreenPoint(pointsList[pointsList.Count-1]));
if(Physics.Raycast(ray,out hit))
{
if(hit.collider)
return true;
}
return false;
}
and also added while checking for collision
if(isLineCollide() && isLineCollidedWithOtherObject())
But it's not working.I added Box2dcollider to platform(Player).Someone please help.
Comment