Hi I’m making a tiny game right now and I have a small issue with the smooth camera movement. When I start playing and move the player around the platform the camera follows the player but the player movement starts lagging and player movement is not smooth. Can someone help me with that? Thanks! Im putting a script of cameraController down below.
camera controller:
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offSet;
private void FixedUpdate()
{
Vector3 desiredPosition = target.position + offSet;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt(target);
}
and player movement script:
public Transform playerTransform;
public CharacterController characterController;
public float speed = 6f;
private void Update()
{
Move();
if (Input.GetKey(KeyCode.Q))
{
playerTransform.transform.Rotate(0f, -1f, 0f);
}
if (Input.GetKey(KeyCode.E))
{
playerTransform.transform.Rotate(0f, 1f, 0f);
}
}
void Move()
{
float HorizontalMove = Input.GetAxis("Horizontal");
float VerticalMove = Input.GetAxis("Vertical");
Vector3 move = transform.forward * VerticalMove + transform.right * HorizontalMove;
characterController.Move(speed * Time.deltaTime * move);
},Hi I'm making a tiny game right now and I have a small issue with the smooth camera movement. When I start playing and move the player around the platform the camera follows the player but the player movement starts lagging and player movement is not smooth. Can someone help me with that? Thanks!
Im putting a script of cameraController down below.
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offSet;
private void FixedUpdate()
{
Vector3 desiredPosition = target.position + offSet;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt(target);
}
}
and also my player movement script:
public Transform playerTransform;
public CharacterController characterController;
public float speed = 6f;
private void Update()
{
Move();
if (Input.GetKey(KeyCode.Q))
{
playerTransform.transform.Rotate(0f, -1f, 0f);
}
if (Input.GetKey(KeyCode.E))
{
playerTransform.transform.Rotate(0f, 1f, 0f);
}
}
void Move()
{
float HorizontalMove = Input.GetAxis("Horizontal");
float VerticalMove = Input.GetAxis("Vertical");
Vector3 move = transform.forward * VerticalMove + transform.right * HorizontalMove;
characterController.Move(speed * Time.deltaTime * move);
}