- Home /
Linecast Layer Mask Declaration Problem
var awareness:float; var aiOwner:GameObject; function OnTriggerStay(other : Collider) { if(other.gameObject.tag =="Player"&&!Physics.Linecast (aiOwner.transform.position,other.transform.position,2)){
other.GetComponent("DetectionScript").NoticedPlaya(awareness);
} }
My scene looks like this
O=======
O is a waypointed AI and ======= are certain triggers for visibility , havign the code above.aiOwner of each trigger is set to the "O"Waypointed AI gameobject The code above uses linecast with the layer mask being 2 for IgnoreRaycast which the triggers have as their layer. The problem is that the linecast doesnt work and its being negative , even when a wall is between the player and the AI , without having set 2 as the linecast's ignore layer, the linecast from the AI hits the triggers and always returns true. Any ideas on how to solve this?
EDIT: OBVIOUSLY im declaring the layer falsely , can someone give me a proper example of how to do it properly?
EDIT 2: after declaring the layer with a valid way , still the problem persists , also , the position where the game thinks aiOwner is isnt at the relative position of the capsule to its parent , it appears its completely random ,its at position
X=30611.73
Y=-6522.702
Z=11684.97
I might be the only one, but seeing "URGENT" is generally a deterrent. Everyone thinks their question is "urgent" or "important", else they wouldn't usually be asking.
Basically it affects one of my game's basic features/functions so it would be best if it would be solved immediately
I never answer questions for free if they are "URGENT". If they are that important, people should pay for answers. Thats whats consulting agencies are for.
Answer by YeOldeSnake 1 · Sep 01, 2010 at 10:17 AM
Got it fixed
var layerMask : int = 1 << 2; layerMask=~layerMask; var awareness:float; //var aiOwner:Transform; var hit:RaycastHit; function OnTriggerStay(other : Collider) {
if(other.gameObject.tag =="Player" && !Physics.Linecast (other.transform.position,transform.parent.position, layerMask)){ other.GetComponent("DetectionScript").NoticedPlaya(awareness); Debug.DrawRay (transform.parent.position* 10,other.transform.position, Color.green);
} }
Answer by burnumd · Aug 30, 2010 at 06:48 PM
You need to use a LayerMask. I imagine what you're looking for is
if(other.gameObject.tag =="Player" && !Physics.Linecast (aiOwner.transform.position, other.transform.position, LayerMask (2)))
If you want to do the math yourself, there are instructions here. In that case you'd use
var layerMask : int = 1 << 2;
if(other.gameObject.tag =="Player" && !Physics.Linecast (aiOwner.transform.position, other.transform.position, layerMask))
hmmm , thats what i had done shortly after i posted the question here , yet to no avail , if i draw a debug ray with that code THIS happens
Your answer
![](https://koobas.hobune.stream/wayback/20220613072335im_/https://answers.unity.com/themes/thub/images/avi.jpg)