OnTriggerEnter
I just started using Unity, so I'm quite new here. I was wondering if anyone could help me with this problem:
The OnTriggerEnter does not always trigger, so I made it so; If the cube touches/collides the road, its speed must get up. Sometimes it works fine, but sometimes it doesn't why is this happening? I have made a short screenrecord about it : https://youtu.be/OSVP17m2a-0 The pastebin link : https://pastebin.com/iFwDckPD
public class Road : MonoBehaviour {
UnityEngine.AI.NavMeshAgent playerAgent;
float speed = 15f;
private bool onRoad = false;
void Update () {
if (onRoad) {
playerAgent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
playerAgent.speed = speed;
}
}
void OnTriggerEnter(Collider other){
if (other.gameObject.CompareTag("Road")) {
onRoad = true;
}
}
void OnTriggerExit(Collider other){
if (other.gameObject.CompareTag("Road")) {
onRoad = false;
}
}
}
Answer by buryo95 · Dec 03, 2017 at 07:33 PM
Oke this was the problem: If you enable navmeshagent, the player won't touch the ground anymore somehow. I still don't know why. But I made the road little bit higher and it worked for me.
Your answer
Follow this Question
Related Questions
Calling "OnTriggerEnter" when a parent object has a rigidbody 0 Answers
Enemy Trigger Colliders are triggering my player's trigger collider. Why? 1 Answer
Problem With Triggers? 0 Answers
OnTriggerEnter not firing 2 Answers
Scripting Portal 0 Answers