Home > Enterprise >  my camera doesn't follow the player when i say start the game
my camera doesn't follow the player when i say start the game

Time:11-09

I'm trying to make a simple hyper casual. I couldn't understand what's wrong with my codes.

My code:

public class CameraFollow : MonoBehaviour
{

  public Transform Target;
  public Vector3   offset;

  void LateUptade()
  {
    transform.position = Vector3.Lerp(transform.position, Target.position   offset, Time.deltaTime * 2);
  }
}

CodePudding user response:

Two Things to note in your code.

  1. Its LateUpdate and not LateUptade.
  2. In lerp If the third input is 1 the camera will instantly jump to target offset and if you want the camera to move slowly from its position to target offse then you need to increase the value of the third input from 0 to 1 every frame.

You can also use Cinemachine to make camera follow player. Check out this Camera follow player tutorial for different ways to make the camera follow player.

CodePudding user response:

Do not put Time.deltaTime in Lerp. The lazy solution is to simply write a constant that is between 0 and 1.

transform.position = Vector3.Lerp(transform.position, Target.position   offset, 0.3f);
  • Related