- Home /
How to use linecast ??
hi my friends. i am working on my simple game. its a ball that have third person shooter camera. i have used Mouse orbit and Smoth Follow scripts. my game works properly but i have a problem with camera. my camera through wall in closed place. i found out that i should use Physics.castline to detect collision between camera and actor (the ball).i wrote this code but its always true ! and never be false.
void Update()
{
if (Physics.Linecast(gameObject.transform.position, wall.transform.position))
{
Debug.Log("collected");
}
if (Physics.Linecast(gameObject.transform.position, wall.transform.position)==false)
{
Debug.Log("not collected");
}
}
does your wall have a collider? if so, this will always return true cause you always intersect it with this line.
yes my walls have colliders. So how i can to fix my problem ?
@3Dmajid2012: If you don't want to answer your own question, don't post answers. I've converted your answer into a comment.
Answer by ScroodgeM · Jul 17, 2012 at 11:03 AM
1 make you ball in individual layer
http://docs.unity3d.com/Documentation/ScriptReference/GameObject-layer.html
2 when you need to check the ball by linecast, filter it by ball's layer
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Linecast.html
or, simply add wall to 'ignore raycast' layer if you needn't raycast them at all
Your answer
![](https://koobas.hobune.stream/wayback/20220613074303im_/https://answers.unity.com/themes/thub/images/avi.jpg)