raycast going through walls
a have a simple scene that has an object and a wall and a player. i am trying to have the object (a camera) see the player if they he or she is in the cameras line of sight. but the problem is that my raycast casts through a wall that the player should be able to hide behind. her is my script. (the collider of the sphere is a size 20 radius so it penetrates the wall) p.s. i am a big noob to unity
#pragma strict
var fieldOfViewAngle : float = 100.0;
var col : SphereCollider;
var hit : RaycastHit;
var vectr3 : Vector3;
function OnTriggerStay (other : Collider) {
var fwd = transform.TransformDirection(Vector3.forward);
var direction : Vector3 = other.transform.position - transform.position;
if(other.CompareTag ("noticeableThing")){
var vectorFromEnemyToPlayer : Vector3 = other.transform.position - transform.position;
var forwardVector = transform.forward;
var angle : float = Vector3.Angle(vectorFromEnemyToPlayer, forwardVector);
if(angle < fieldOfViewAngle * 0.5f) {
if(Physics.Raycast(transform.position + transform.up, direction.normalized, hit, col.radius)){
if (hit.collider.tag == "noticableThing");
print("HA");
}
}
}
}
function Awake () {
col = GetComponent(SphereCollider);
}
Please use code tags and format your question properly. It's a matter of respect by showing that you are willing to put the same effort as we into your questions.
well I thought i was doing it right. what did I fail at?
so what is it I need 2 fix? just take out "hashtag pragma strict"?
Your answer
Follow this Question
Related Questions
ScreenPointToRay 0 Answers
Check if position is inside a collider 5 Answers
Object moving fast keeps "climbing" walls 1 Answer