Hello, I need assistance with my Unity Project. Normally the jittery camera comes from when the camera tries to update before the player is finished moving, but for some reason in this case the character is the one jittering on their own. I’m pretty stumped as why the character is jittering. They physics code is based off of the 2D custom gravity course.
PhysicsObject2D:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PhysicsObject2D : MonoBehaviour
{
//Editable Variables
public float gravConstant = 1f; //Modification to Physics Gravity
//Class Variables
private Rigidbody2D _rb2d; //Reference to RigidBody2D
private Vector2 velocity; //Velocity of the object
private void OnEnable()
{
_rb2d = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
//Increase downward velocity while in the air
velocity += gravConstant * Physics2D.gravity * Time.deltaTime;
//Move object
Vector2 move = Vector2.up * velocity.y * Time.deltaTime;
_rb2d.position += move;
}
}
CameraFollow:
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
//Public Variables
public Transform target; //Camera Target
public float smoothSpeed = 0.125f; //Camera lag speed
public Vector3 offset; //Offset for the camera position
private void LateUpdate()
{
//Get Desired camera position - Player's position
Vector3 desiredPosition = target.position + offset;
//Smooth the camera's movement using linear interpolation
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
//Apply the lerped position
transform.position = smoothedPosition;
}
}