I’m sorry, but I’m still having issues with jittering even though I helped it by putting the camera in lateupdate and making the car interpolate, the jitter still appears, though less than before.
98i2ng
Here are my vehicle, engine sound, and camera code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarControlla : MonoBehaviour
{
public enum Axel
{
Front,
Rear
}
[Serializable]
public struct Wheel
{
public Transform WheelMesh;
public WheelCollider WheelCollider;
public Axel axel;
}
public Rigidbody arbees;
Vector3 pos;
Quaternion quat;
public float Toque, RotSpeed, maxSteerAngle;
public float addDownForceValue = 50;
public GameObject mas;
public float MPH;
public float maxSpeed = 200;
public static float Turn;
public List<Wheel> wheels;
void Start()
{
arbees = GetComponent<Rigidbody>();
mas = GameObject.Find("mASS");
arbees.centerOfMass = mas.transform.localPosition;
}
// Update is called once per frame
void FixedUpdate()
{
MoveDaCar();
SteerDaCar();
}
private void AddDownForce()
{
arbees.AddForce(-transform.up * addDownForceValue * arbees.velocity.magnitude);
}
private void MoveDaCar()
{
foreach (var wheel in wheels)
{
wheel.WheelCollider.GetWorldPose(out pos, out quat);
wheel.WheelMesh.position = pos;
wheel.WheelMesh.rotation = quat;
}
foreach (var wheel in wheels)
{
wheel.WheelCollider.motorTorque = Input.GetAxis("Vertical") * Toque * 1000f * Time.deltaTime;
}
MPH = arbees.velocity.magnitude * 15;
if (MPH > maxSpeed)
{
arbees.velocity = Vector3.ClampMagnitude(arbees.velocity, maxSpeed);
}
AddDownForce();
}
private void SteerDaCar()
{
foreach(var wheel in wheels)
{
Turn = Input.GetAxis("Horizontal") * RotSpeed * 3 * Time.deltaTime;
Quaternion rotateLR = Quaternion.Euler(0f, Turn, 0f);
arbees.MoveRotation(arbees.rotation * rotateLR);
if (wheel.axel == Axel.Front)
{
var _steerAngle = Turn * RotSpeed * maxSteerAngle;
wheel.WheelCollider.steerAngle = Mathf.Lerp(wheel.WheelCollider.steerAngle, _steerAngle, 0.3f);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour
{
public Transform target;
public float translateSpeed;
public float rotSpeed;
// Update is called once per frame
void LateUpdate()
{
transform.position = Vector3.Lerp(transform.position, target.position, translateSpeed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, rotSpeed * Time.deltaTime);
transform.rotation = Quaternion.Euler(new Vector3(0, transform.rotation.eulerAngles.y, 0));
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EngineCarSound : MonoBehaviour
{
public AudioSource EngineSound;
public Rigidbody carArbees;
float velocityMagnitude;
float engineVolume;
float enginePitch = 0.5f;
// Start is called before the first frame update
void Start()
{
EngineSound = GetComponent<AudioSource>();
carArbees = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
EngineNoise();
}
void EngineNoise()
{
velocityMagnitude = carArbees.velocity.magnitude;
engineVolume = velocityMagnitude * 0.05f;
engineVolume = Mathf.Clamp(engineVolume, 0.2f, 1.0f);
EngineSound.volume = Mathf.Lerp(EngineSound.volume, engineVolume, Time.deltaTime * 10);
enginePitch = velocityMagnitude * 0.2f;
enginePitch = Mathf.Clamp(enginePitch, 0.5f, 1f);
EngineSound.pitch = Mathf.Lerp(EngineSound.pitch, enginePitch, Time.deltaTime * 1.5f);
}
}