Camera wont lock to car "simple follow camera" lesson

HI Nina,

My camera doesn’t lock onto the car when I push play. I moved it over to the car just to make sure i had the camera distance and frame size right. ThingToFollow is set to my car. The camera does move with my wasd keys but, it doesn’t follow the car really and moves very slowly

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class FollowCamera : MonoBehaviour

{

[SerializeField] GameObject thingToFollow;



//movement speed in units per second

private float movementSpeed = 5f;

void LateUpdate()

{

    //get the Input from Horizontal axis

    float horizontalInput = Input.GetAxis("Horizontal");

    //get the Input from Vertical axis

    float verticalInput = Input.GetAxis("Vertical");

    //update the position

    transform.position = transform.position + new Vector3(horizontalInput * movementSpeed * Time.deltaTime, verticalInput * movementSpeed * Time.deltaTime, 0);

    //output to log the position change

    Debug.Log(transform.position);

}

}

Hi MrFool,

Have you already read your code in LateUpdate whether it makes sense? For example, where does thingToFollow get used in your code? (Remember you can also look at the lecture code changes via the link in the Resources of each lecture.)

Thank you for the clue!

I figured thingToFollow needed to actually be used in the code. Made sense when I saw the changes in the log.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms