Raycast doesn't work.

Hello, I’m new in unity. I’ve been doing a FPS game, with enemies.

I’ve started doing the sight of the enemies, but doing the debug, something happened.

Sight only worked when the enemy collided with something that was not the terrain.

Here’s my code. I’ll appreciate any solutions.

using UnityEngine;
using System.Collections;

public class EnemyVisionRaycast : MonoBehaviour {

	private Vector3 dir;
	// Update is called once per frame
	void FixedUpdate () {
		RaycastHit hit;
		dir = transform.rotation.eulerAngles;
		Ray vision = new Ray (transform.position, dir);
		Debug.DrawRay(transform.position,dir,new Color(0,0,0,100));
		if (Physics.Raycast (vision,out hit, 100))
		{
			if (hit.collider.CompareTag ("PlayerTag")) {
				Debug.Log ("It works");
			}

		}
	}
}

Oh, the enemy is a prefab.

-AlexINF

try changing dir = transform.rotation.eulerAngles to dir = transform.forward … plus, make sure that the gameobject that your ray is colliding with has a “playerTag” tag … this is what i can tell you for now as your question does not have enough info … PLease accept my answer if it solved your problem