- Home /
Question by
Pro101YT · Jun 20, 2021 at 09:28 AM ·
cameracamera-movement
Camera movement stuttery with interpolate on,Camera movement with interpolate on?
I have been trying to implement camera movement into my car game but with interpolate on the camera is stuttery but without interpolate the turning is stuttery. please help.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
[SerializeField] private Vector3 offset;
[SerializeField] private Transform player;
[SerializeField] private float translateSpeed;
[SerializeField] private float rotationSpeed;
private void FixedUpdate()
{
HandleTranslation();
HandleRotation();
}
private void HandleTranslation()
{
var playerPosition = player.TransformPoint(offset);
transform.position = Vector3.Lerp(transform.position, playerPosition, translateSpeed * Time.deltaTime);
}
private void HandleRotation()
{
var direction = player.position - transform.position;
var rotation = Quaternion.LookRotation(direction, Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, rotationSpeed * Time.deltaTime);
}
}
Comment