- Home /
Moving trigger collider and raycast doesnt detect anything
Okay so i have an enemy and a wall and a player. the enemy goes towards player and through wall because its not static. Thing is that i have an extra collider on enemy which is a trigger. It uses this script: using UnityEngine; using System.Collections; public class YetAnotherTryAtAI : MonoBehaviour { public GameObject node; public float rayRange; private NavMeshAgent agent; public Vector3 playerPos; public GameObject player; void Start() { agent = GetComponent<NavMeshAgent>(); } void Update() { playerPos = player.transform.position; agent.SetDestination(playerPos); } void OnTriggerEnter (Collider other) { print ("Something enters"); if (other.collider.tag == "Obstacle") { print("Obstacle"); } } }
It doesnt print anything so i tried raycasting: using UnityEngine; using System.Collections; public class YetAnotherTryAtAI : MonoBehaviour { public GameObject node; public float rayRange; private NavMeshAgent agent; public Vector3 playerPos; public GameObject player; void Start() { agent = GetComponent<NavMeshAgent>(); } void Update() { RaycastHit hit; Ray ray = new Ray (transform.position, Vector3.forward); Debug.DrawRay (transform.position, transform.forward * rayRange); if (Physics.Raycast (ray, out hit, rayRange)) { print("Something something dark side"); if(hit.collider.tag == "Obstacle"){ print("Obstacle"); } } playerPos = player.transform.position; agent.SetDestination(playerPos); } }
Anyways that doesnt work either. I did fill out all the floats and set the public objects but yeh nothing..