Hello all. I’m having a tough time with something very simple…
So I’m just trying to get a basic design done: get a turret to follow my player. The only objects in my scene are…
- A floor made of planes
- 1 cube
- 1 player controller (camera, etc)
I’ve made a cube and attached a script that should work. Here is the code.
using UnityEngine;
using System.Collections;
public class turretFollow : MonoBehaviour
{
public Transform target;
void OnTriggerStay(Collider col)
{
if (col.tag == "Player")
{
transform.LookAt (target);
}
}
}
The cube does indeed have a collider that is set to trigger. It is a box collider. I’ve made it wide and long, so that it’s view is large. Once I step into the box collider, it grabs only for a moment where I entered, and stays there. Once I get really close to the cube, then it starts to follow as intended. If I take a few steps back, it no longers follows me (even though I am still inside the collider box.)
My player controller is tagged as “Player”
The “target” variable has been checked in the inspector as the player controller
What is going on?
I couldn’t find any tutorials or other forum posts about this specific problem.