Been looking around at the 50 billion turret tuts on the net. Still having a problem…
public class SlowTurretController : MonoBehaviour {
public GameObject targetFollow;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.LookAt(targetFollow.transform);
}
}
The turret is rotated at a weird angle when I playtest the scene, suggesting it’s trying to follow the player…sort of, but it won’t update after the initial load…
It’s a bit confusing because you have 2 different camera angles in your screenshots. LookAt points the object’s Z axis at the target Vector3, so it would appear to be doing exactly what it’s supposed to - pointing the center of the cylinder at the capsule.
It definitely rotates, once anyway when the level first starts. Beyond that initial movement though it never moves again.
transformlookat should make it look at the player every frame should it not? Right now it only looks once and then stops, even though I have it in void update. Or am I supposed to give it a condition to check to see if the player has moved before trying again?
Is this a better example?
Anyway, nothing seems to be happening now. So maybe I was mistaken about it actually moving.
The turret is the box. As you can see I moved the player and the turret did not move.
However I added a print at the end of the code and that’s updating every frame so it’s definitely running through the code, it’s just not doing anything I can see.
Alright, I made this real quick. A cylinder, with a fire particle on it. Run (LShift) or walk WASD around the cylinder and the cylinder and fire follow you.
Target (named dude) and code from previous post is attached to cylinder. The flame is a child object of the cylinder. Hope it helps somewhat. I think it just wasn’t locating your object.