I have a project in which the terrain has lots of trees, lots of detail meshes and post processing applied is on the camera. It is kind of a racing game that I am making. The camera appears to severely jitter on this terrain, however if I import the car prefab, apply the scripts and everything on a completely fresh and plain terrain in another scene, there isn’t even a hint of jitter.
Why does this happen and how do I solve it? Please help!
Car Controller script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public Rigidbody sphereRB;
public float speed;
public float rotateForce;
public LayerMask groundLayer;
bool isCarGrounded;
float moveInput;
void Start ()
{
sphereRB.transform.parent = null;
}
void Update ()
{
moveInput = Input.GetAxisRaw("Vertical");
moveInput *= speed;
Debug.Log(moveInput);
transform.position = sphereRB.transform.position;
if (Input.GetAxis("Vertical") != 0 && Input.GetAxis("Horizontal") != 0)
{
foreach( TrailRenderer trail in GetComponentsInChildren<TrailRenderer>())
{
trail.emitting = true;
}
} else
{
foreach (TrailRenderer trail in GetComponentsInChildren<TrailRenderer>())
{
trail.emitting = false;
}
}
}
void FixedUpdate ()
{
RaycastHit hit;
isCarGrounded = Physics.Raycast(transform.position, -transform.up, out hit, groundLayer);
transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
if (isCarGrounded)
{
sphereRB.transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal"), 0f);
transform.Rotate(0f, rotateForce * Input.GetAxis("Horizontal") * Input.GetAxis("Vertical"), 0f);
sphereRB.AddForce(transform.forward * moveInput, ForceMode.Acceleration);
}
}
}
Camera follow script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform camPosTarget;
public Transform camLookTarget;
void FixedUpdate()
{
transform.LookAt(camLookTarget);
transform.position = Vector3.Lerp(transform.position, camPosTarget.position, 10f * Time.deltaTime);
}
}