Hi everyone,
I’m noob and need to help with this camera stuttering thing. The video speaks for itself so I’m gonna add the code and settings.
The camera is a child of the player object but even when its not the same issue occurs with the issue being not that visible but still there. I tried to move the movement code to LateUpdate, Update and FixedUpdate but nothing makes it better. I also tried to move the camera out of the player prefab and make the camera movement and rotation on LateUpdate but that didn’t help either.
Does anyone have a tip what else to try?
Thank you people!
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public float smoothTime = 0.3f;
public float rotationSpeed = 5;
public float rotateHorizontal;
private Rigidbody2D rb;
private Vector2 mv;
private bool dashing=false;
private Vector2 zeroVelocity = Vector2.zero;
void Awake()
{
rb = this.GetComponent<Rigidbody2D>();
Cursor.visible = false;
}
void Update()
{
rotateHorizontal = -Input.GetAxis("Mouse X");
Vector3 mi = new Vector2(0,0);
if (Input.GetKey(KeyCode.W))
mi += transform.up;
if (Input.GetKey(KeyCode.S))
mi -= transform.up;
if (Input.GetKey(KeyCode.A))
mi -= transform.right;
if (Input.GetKey(KeyCode.D))
mi += transform.right;
float jump = (20 * Input.GetAxisRaw("Jump"));
if (jump != 0)
dashing = true;
else
dashing = false;
if (jump == 0)
jump = 1f;
mv = mi.normalized * speed * jump;
}
private void FixedUpdate()
{
if (dashing)
rb.AddForce(mv);
else
{
rb.velocity = Vector2.SmoothDamp(rb.velocity, mv, ref zeroVelocity, smoothTime);
}
rb.MovePosition(rb.position + mv * Time.fixedDeltaTime); //this is even worse
transform.RotateAround(transform.position, transform.forward, (rotateHorizontal) * rotationSpeed); //this in Update makes it worse
}
}