[RESOLVED]Raycast problem

I have an enemy that goes between wapoints and if the player is in a certain area then chase. However i want to do a raycast from the enemy to the player so that if the player is standing behind a wall but still in the chase distance then it wont chase the player.

It seems very simple but for some reason the raycast is getting the better of me. I want it to change a boolean to false if the enemy can see it but there isn’t a wall between.

here’s the snippet of my script i am working on.
I have defined the player as a transform with tag Player
The draw line works.

function Update () {
	
   var hit : RaycastHit;    
	Debug.DrawLine(transform.position, player.position, Color.red);
	
	if(Physics.Raycast(transform.position, player.transform.position, hit)) {
		
		if(hit.collider.gameObject.name == "player") {
		
			touchingWall = false;
			Debug.Log("touching wall false");
		
		} else {
		
			touchingWall = true; 
			Debug.Log("touching wall true");
		
		}
	}
   }

Raycast() doesn’t want two positions; it wants one position and a direction (for example, by subtracting your target’s position from your own, you can get a vector pointing from yourself to your target).

You might be thinking of Physics.Linecast(), which does take two positions.

@rutter is right: usually Linecast is the best choice in this case - but you must check if the object hit by the line is the target you’re looking for: if it’s not, you have something in between.

var target2 : Transform;

function Update () {
  var hit: RaycastHit;
  if (Physics.Linecast(transform.position, target2.position, hit)){ // if line hits something...
    if (hit.transform == target2){ // and it's the target...
      print("I can see you!"); 
    } else { 
      print("Something hides the target"); 
    }
  }
}