I’m trying to make a follow camera for this little rocket game, but whenever the rocket moved the camera was choppy, so I looked up why it did that and I found a forum post saying something about damping. So i turned off damping and it was fine when it moved, but when it rotated it was choppy again. Could I get some help?
Can you please post an image of your vcam inspector, taken while the game is playing?
Maybe we should back up a little, because looking at your inspector I don’t know what you’re trying to do so it’s hard for me to help.
Can you give some game context? (i.e. 2D, 3D, what kind of game)
Can you describe how the rocket is moving?
Can you describe how you would like the camera to move?
This is a 3D game with low gravity, the rocket is rotating with the A and D keys and it moves in the direction that it is pointing when I press space. I use Rigidbody for movement and transform.Rotate for rotating along the z-axis. I would like the camera to move along the x-axis in the direction the rocket goes.
That has not appeared to have changed anything. It is still very choppy.
Maybe I don’t understand what you mean when you say “choppy”. A video would help.
You mentioned that you are using RigidBody to drive your rocket. You might be facing a FixedUpdate vs Update inconsistency. That would give a certain kind of choppiness. I had asked you to show the vcam inspector when the game was playing. This is because when it is playing, the vcam update mode is indicated to the right of the Solo button on the inspector. What does it say?
Also, can you show an image of the CinemachineBrain inspector?
how do I send you a video on here?
You can paste a gif, or you can upload it somewhere and paste a link
ek3v1c
Thanks. It does look like an update clock issue. I still didn’t see the vcam inspector while the game was playing.
Try enabling Interpolation on the rocket’s RigidBody.
I turned on interpolation but it’s still choppy. 9m2lio
ok, I can see that the vcam is updating in LateUpdate. I think the cameras are set up correctly.
How are you moving the rocket? Can you show the code?
Hang on, I think the problem is here. You must use the RigidBody exclusively for moving the rocket. Never touch the transform directly. Just add forces to the RB, otherwise interpolation won’t work properly.
This is my movement script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
[SerializeField] float mainThrust = 0;
[SerializeField] float rotationThrust = 0;
[SerializeField] AudioClip mainEngine;
[SerializeField] ParticleSystem mainThrusterParticles;
[SerializeField] ParticleSystem leftThrusterParticles;
[SerializeField] ParticleSystem rightThrusterParticles;
Rigidbody rb;
AudioSource audioSource;
void Start()
{
rb = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
void Update() {
ProcessThrust();
ProcessRotation();
}
void ProcessThrust() {
if (Input.GetKey(KeyCode.Space))
{
StartThrusting();
}
else
{
StopThrusting();
}
}
void StartThrusting() {
rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(mainEngine);
}
if (!mainThrusterParticles.isPlaying)
{
mainThrusterParticles.Play();
}
}
void StopThrusting() {
audioSource.Stop();
mainThrusterParticles.Stop();
}
void ProcessRotation() {
if (Input.GetKey(KeyCode.A))
{
RotateLeft();
}
else if (Input.GetKey(KeyCode.D))
{
RotateRight();
}
else
{
StopRotating();
}
}
void RotateLeft()
{
ApplyRotation(rotationThrust);
if (!rightThrusterParticles.isPlaying)
{
rightThrusterParticles.Play();
}
}
void RotateRight()
{
ApplyRotation(-rotationThrust);
if (!leftThrusterParticles.isPlaying)
{
leftThrusterParticles.Play();
}
}
void StopRotating()
{
rightThrusterParticles.Stop();
leftThrusterParticles.Stop();
}
void ApplyRotation(float rotationThisFrame)
{
rb.freezeRotation = true; // freezing rotation so we can manually rotate
transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);
rb.freezeRotation = false; // unfreezing rotation so the physics system can take over
}
}
Yeah, it’s this:
transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);
You can’t mix RB and transform movement. Do everything with forces in RB.
Also, you should be applying forces in FixedUpdate, not in Update, I think.
I think the camera is unfixable for this game, I’m making this game while following a C# course and I haven’t learned that much about RB movement yet, I came here because I wanted to see if there was a way I could fix the camera, the instructor for the course said I can either make it a static camera or follow the player. I think ill just deal with the slight choppiness. Sorry if i wasted your time.
The way to fix it is to fix the rocket movement. It’s impossible to have a camera smoothly track an object that moves unevenly. Either the object will jitter in the frame, or if you turn off camera damping the object will be in a fixed position on the screen (so it won’t jitter) but it will be ugly, and the background will jitter (although that’s less noticeable to the viewer).
Sorry, I should’ve phrased that better. I am still learning how to code C# and I don’t know how to turn an object with code and RB. It is possible, but I don’t know how to do it yet.