#Camera jitter

1 messages · Page 1 of 1 (latest)

white flax
grand dawn
rancid shell
#

I'm not seeing camera jitter. Whatever the red object there is is being moved incorrectly or updated incorrectly

white flax
# grand dawn https://unity.huh.how/mouse-input-and-deltatime

using UnityEngine;

public class CameraHandler : MonoBehaviour
{
#region VARIABLES
[Header("Objects")]
[SerializeField] Transform Player;

[Header("Settings")]
[SerializeField] float RotationSpeed;
[SerializeField] float Sensitivity;
[SerializeField] float GamepadSensitivity;
[SerializeField] float MaxY;
[SerializeField] Vector3 Offset;

[Header("Variables")]
[SerializeField] Vector2 MousePos;
public float HorizontalLook;
public float VerticalLook;

[Header("Scripts")]
[SerializeField] InputHandler InputHandler;
[SerializeField] MovementHandler MovementHandler;
#endregion

#region MAIN
private void Update()
{
    bool UsingStick = InputHandler.GetDevice() == "Gamepad" ? true : false;
    float NewSensitivy = UsingStick ? Sensitivity * GamepadSensitivity : Sensitivity;

    // Get Mouse look direction
    MousePos = InputHandler.GetInput("Look").ReadValue<Vector2>();
    HorizontalLook += MousePos.x * NewSensitivy;
    HorizontalLook = (HorizontalLook + 360) % 360; // Cap to 360

    VerticalLook -= MousePos.y * (NewSensitivy / 2);
    VerticalLook = Mathf.Clamp(VerticalLook, -MaxY, MaxY); // Limit cam vertical

    HandleCamTransform();
}
#endregion

#region CAM MOVEMENT
private void HandleCamTransform()
{
    Quaternion TargetRot = Quaternion.Euler(VerticalLook,HorizontalLook,0);

    transform.position = Player.position - TargetRot * Offset;
    transform.rotation = TargetRot;
    Player.rotation = Quaternion.Slerp(Player.rotation,Quaternion.LookRotation(MovementHandler.MoveDirection),Time.deltaTime * RotationSpeed);
}
#endregion

}

white flax
#

the red object js helps see the issue better

rancid shell
#

Sure, but the objects in the background arent jittering though

white flax
#

ye idk why

#

i think it s this line

    Quaternion TargetRot = Quaternion.Euler(VerticalLook, HorizontalLook, 0f);
    Vector3 TargetPos = Player.position + TargetRot * Offset;

    // Set camera position and rotation
    CamHolder.SetPositionAndRotation(TargetPos,TargetRot);
rancid shell
#

just seems like the character isnt interpolating correctly

white flax
#

since ur applying the horizontal look to change the cameras rotation position and the players rotation

#

i think thats the issues cause

rancid shell
#

Really I'd do yourself a favor and look into cinemachine which would help determine if it is a camera issue as those are disjointed from the player and will smooth itself out

white flax
#

i rlly dont wanna use cinemachine and doubt its gonna help

#

i feel like im js doing a calculation wrong or smthn

white flax
#
using UnityEngine;

public class CameraHandler : MonoBehaviour
{
    #region VARIABLES
    [Header("Objects")]
    [SerializeField] Transform Player;

    [Header("Settings")]
    [SerializeField] float Sensitivity;
    [SerializeField] float GamepadSensitivity;
    [SerializeField] float MaxY;
    [SerializeField] Vector3 Offset;

    [Header("Variables")]
    [SerializeField] Vector2 MousePos;
    public float HorizontalLook;
    public float VerticalLook;

    [Header("Scripts")]
    [SerializeField] InputHandler InputHandler;
    #endregion

    #region MAIN
    private void Update()
    {
        bool UsingStick = InputHandler.GetDevice() == "Gamepad" ? true : false;
        float NewSensitivy = UsingStick ? Sensitivity * GamepadSensitivity : Sensitivity;

        // Get Mouse look direction
        MousePos = InputHandler.GetInput("Look").ReadValue<Vector2>();
        HorizontalLook += MousePos.x * NewSensitivy;
        HorizontalLook = (HorizontalLook + 360) % 360; // Cap to 360

        VerticalLook -= MousePos.y * (NewSensitivy / 2);
        VerticalLook = Mathf.Clamp(VerticalLook, -MaxY, MaxY); // Limit cam vertical

        HandleCamTransform();
    }
    #endregion

    #region CAM MOVEMENT
    private void HandleCamTransform()
    {
        Quaternion TargetRot = Quaternion.Euler(VerticalLook,HorizontalLook,0);

        transform.position = Player.position - TargetRot * Offset;
        transform.rotation = TargetRot;
    }
    #endregion
}
#
using UnityEngine;
 
public class MovementHandler : MonoBehaviour
{
    #region VARIABLES
    [Header("Objects")]
    [SerializeField] Rigidbody RB;
 
    [Header("Settings")]
    // Movement
    [SerializeField] float MoveSpeed;
    [SerializeField] float SprintSpeed;
    [SerializeField] float AirSpeed;
    // Jump
    [SerializeField] float JumpPower;
    [SerializeField] float JumpCD;
 
    [Header("Variables")]
    [SerializeField] float CurrentSpeed;
    public Vector3 MoveInput;
    public Vector3 MoveDirection;
 
    [Header("Scripts")]
    [SerializeField] InputHandler InputHandler;
    [SerializeField] CharacterHandler CharacterHandler;
    [SerializeField] CooldownHandler CooldownHandler;
    [SerializeField] CameraHandler CameraHandler;
    #endregion

    #region MAIN
    private void Update()
    {
        Vector2 RawMove = InputHandler.GetInput("Move").ReadValue<Vector2>();
        MoveInput = new Vector3(RawMove.x, 0f, RawMove.y);
    }
 
    private void FixedUpdate()
    {
        HandleMovement();
        HandleJump();
    }
    #endregion

    #region WALK + SPRINT
   
    private void HandleMovement()
    {
        // Rotate player
        if (MoveInput == Vector3.zero)
        {
            CurrentSpeed = 0;
            RB.linearVelocity = new Vector3(0, RB.linearVelocity.y, 0);
            return;
        }
 
        Quaternion CamDirection = Quaternion.Euler(0,CameraHandler.HorizontalLook,0);
        CurrentSpeed = CalculateSpeed();
        MoveDirection = new Vector3(MoveInput.x, 0f, MoveInput.z).normalized;
        MoveDirection = CamDirection * MoveDirection * CurrentSpeed;

        RB.linearVelocity = new Vector3(MoveDirection.x, RB.linearVelocity.y, MoveDirection.z);
        transform.rotation = Quaternion.LookRotation(MoveDirection);
    }
    #endregion
 
    #endregion
white flax
#

Ive tried everything every combination every update fixed update late update everything im starting to think its not the code and its something else

mild warren
# white flax

Interpolation would be broken if you move or ratate the transform directly. You need to apply angular velocity or torque to the rb. Move rotation might work as well.

white flax
#

I wish u came 10 mins earlier i was abt to sleep

#

Could u perhaps tell me how to do that

#

Ive never heard of torque or angular vel

mild warren
#

Check the rigidbody documentation. It has several ways to rotate it.

white flax
#

But how come in the tut i watched he js used rotation =

mild warren
#

Angular velocity is like setting the linear velocity, but for rotation. Torque is like force but for rotations.

white flax
#

I was trying to use this at first

https://www.youtube.com/watch?v=DXw9QhsjlME

Checkout the full Third Person Parkour System Course here - https://fantaco.de/unity-parkour-system
Get our Advanced Parkour and Climbing System Asset - https://prf.hn/l/y8kYEa4/

Hey everyone, in this video we'll create a Third Person Controller in Unity. We won't be using any assets to build it, we'll build it completely from scratch because ...

▶ Play video
mild warren
white flax
#

So should i use angular vel and torque

#

Its js ive never seen anyone use that

mild warren
#

Yes. Probably angular velocity, to keep consistency with linear velocity

white flax
#

Ive always seen people use rotation or moverotation

#

Btw it doesnt only jitter when walking it happens as long as im moving the cam to rotate the player

mild warren
mild warren
mild warren
white flax
#

All of this uodate and fixed update stuff is so annoying

#

Like it js feels likd ive tried everything

#

Ive lost all hope that anythings gonna work or that its my code

mild warren
#

Instead of "trying everything" you should understand the underlying cause first.

white flax
#

Ive had to change my code so many times that i dont evene know what's happening

#

I asked chat gpt and even he couldnt fix it

#

So theres no way its my code

#

Cause i spent hrs with gpt trying everything and nothing worked

mild warren
#

It is. Don't just assume chat gpt is better than a real experienced developer... That's a bit insulting...

white flax
#

Thats why i don't believe its my code

#

But still

#

I asked so many people in the server too

#

No one could figure it out

#

And a while back i made a first person game it was stuttering but it wasnt my code it was a setting or smthn

mild warren
#

Well, your code and the context you shared is a bit convoluted, so you have to make many assumptions to provide a decent advice to you. No one likes doing that.

#

Anyways, whether it's an issue in your code or not, understanding the underlying cause, instead of blindly applying random solutions, would help you fix it correctly.

white flax
#

How could i find the cause

#

Everything in inspector looks fine

#

What if its because im using the mouse pos to decide the cams rot and to decide where ur gonna walk and to decide where ur gonna face

#

Since move direction and targer rot both use it

#

In my older code the jitter was alot worse i think its at the top of the thread

mild warren
#

Well, think logically. Stuttering is a result of object updates(position or rotation) not being aligned with rendering rate. Rendering rate is equal to regular update. Rigidbodies by default update in fixed update, which is at different rate than regular update. Interpolation is supposed to interpolate the changes to the objects in normal update and thus align it with rendering, but it can be broken due to various mistakes, like moving or updating the object via transform.

#

Then there's the issue of understanding what exactly is misaligned. It can be an object in the view, or even the camera itself.

#

One way you can test alignment is by logging the change in position/rotation of a suspect in update while reproducing the issue. If you see inconsistent numbers, then the suspect is not aligned with rendering rate.

white flax
mild warren
#

It's not updating at the same rate as rendering.

#

One frame it rotates 5 degrees, another 20, then 0, then 30. Something like that. The numbers are exaggerated a bit.

#

Instead it should be like 15 degrees on all frames. Or increase/decrease gradually if some kind of smoothing is in effect.

white flax
#

Oh so like if its not rotating it similar intervals its bad

mild warren
#

Yes. It's not consistent. That's what jitter is basically.

white flax
#

So if i log the cam rot and 1 frame it says 10 then the next is 50 then the next is 60 then thats bad right

#

After i find out if the cam or player is causing jitter what do i do

mild warren
#

You make it consistent. Refer to what I said earlier about RBs.

white flax
#

Alr tysm i will try when i wake up since its 2 am 😭

#

Tysm for everything

white flax
#

Yo @mild warren

mild warren
white flax
#

oh 😭

#

alr im gonna keep trying ig thanks

mild warren
#

Or maybe you should share the code that prints these logs...

#

So that I can know what it means...

white flax
#

Alr i will when im home

white flax
#

@mild warren heres the code

MovementHandler

using UnityEngine;
 
public class MovementHandler : MonoBehaviour
{
    #region VARIABLES
    [Header("Objects")]
    [SerializeField] Rigidbody RB;
 
    [Header("Settings")]
    // Movement
    [SerializeField] float MoveSpeed;
    [SerializeField] float SprintSpeed;
    [SerializeField] float AirSpeed;
 
    [Header("Variables")]
    [SerializeField] float CurrentSpeed;
    public Vector3 MoveInput;
    public Vector3 MoveDirection;
 
    [Header("Scripts")]
    [SerializeField] InputHandler InputHandler;
    [SerializeField] CharacterHandler CharacterHandler;
    [SerializeField] CooldownHandler CooldownHandler;
    [SerializeField] CameraHandler CameraHandler;
    #endregion

    #region MAIN
    private void Update()
    {
        Vector2 RawMove = InputHandler.GetInput("Move").ReadValue<Vector2>();
        MoveInput = new Vector3(RawMove.x, 0f, RawMove.y);

        if (MoveInput == Vector3.zero) return;
        Quaternion CamDirection = Quaternion.Euler(0, CameraHandler.HorizontalLook, 0);
        Vector3 Raw = new Vector3(MoveInput.x, 0f, MoveInput.z);
        MoveDirection = (CamDirection * Raw).normalized;
    }
 
    private void FixedUpdate()
    {
        HandleMovement();
        HandleJump();
    }
    #endregion
 
    #region MOVEMENT
 
    #region WALK + SPRINT
    private void HandleMovement()
    {
        RB.MoveRotation(Quaternion.Euler(0,CameraHandler.HorizontalLook,0));
        CurrentSpeed = CalculateSpeed();

        if (MoveInput == Vector3.zero)
        {
            RB.linearVelocity = new Vector3(0f, RB.linearVelocity.y, 0f);
            return;
        }

        Vector3 FinalDirection = MoveDirection * CurrentSpeed;
        RB.linearVelocity = new Vector3(FinalDirection.x, RB.linearVelocity.y, FinalDirection.z);

        // RB.MoveRotation(Quaternion.LookRotation(MoveDirection));
    }
    #endregion
 
    #endregion
}
#

CameraHandler

using UnityEngine;

public class CameraHandler : MonoBehaviour
{
    #region VARIABLES
    [Header("Objects")]
    [SerializeField] Transform Player;
    [SerializeField] Transform CamHolder;
    [SerializeField] Transform Pivot;

    [Header("Settings")]
    [SerializeField] float Sensitivity;
    [SerializeField] float GamepadSensitivity;
    [SerializeField] float MaxY;
    [SerializeField] Vector3 Offset;

    [Header("Variables")]
    [SerializeField] Vector2 MousePos;
    public float HorizontalLook;
    public float VerticalLook;

    [Header("Scripts")]
    [SerializeField] InputHandler InputHandler;
    [SerializeField] MovementHandler MovementHandler;
    #endregion

    #region MAIN
    private void Update()
    {
        bool UsingStick = InputHandler.GetDevice() == "Gamepad" ? true : false;
        float NewSensitivy = UsingStick ? Sensitivity * GamepadSensitivity : Sensitivity;

        // Get Mouse look direction
        MousePos = InputHandler.GetInput("Look").ReadValue<Vector2>();
        HorizontalLook += MousePos.x * NewSensitivy;
        HorizontalLook = (HorizontalLook + 360) % 360; // Cap to 360

        VerticalLook -= MousePos.y * (NewSensitivy / 2);
        VerticalLook = Mathf.Clamp(VerticalLook, -MaxY, MaxY); // Limit cam vertical
    }

    private void LateUpdate()
    {
        HandleCamTransform();
    }
    #endregion

    #region CAM MOVEMENT

    private void HandleCamTransform()
    {
        Quaternion TargetRot = Quaternion.Euler(VerticalLook,HorizontalLook,0);

        CamHolder.position = Player.position - TargetRot * Offset;

        CamHolder.rotation = Quaternion.Euler(0f, HorizontalLook, 0f);
        Pivot.localRotation = Quaternion.Euler(VerticalLook, 0f, 0f);
    }
    #endregion
}
white flax
#

Rn it feels like im walking in low fps

white flax
stuck trout
#

I didn't read the entire thread but probably one of three things

  • one of them you update in fixedUpdate, the other in Update
  • you update both in fixedUpdate and you have rigidbody2d interpolation enabled
  • your override the rigidbody2d not accurately, causing the interpolation to miss. This is the worst case
glad atlas
#

@white flax
Do you have VSync (Game view) on? - it's in the same menu where it says Free Aspect.
Is the camera a child object of the Player GameObject? Perhaps, within a Rigidbody?
Do all your Rigidbody components have Interpolation on (or Extrapolation if you prefer that)

white flax
glad atlas
#

As rule of thumb, the methods for moving rigidbodies that are optimal and don’t cause side effects are
Non-Kinematic: AddForce, AddTorque and their variants (AddTorqueAtPosition etc)
Kinematic: MovePosition, MoveRotation

white flax
#

rotation is my issue

#

what i think is that when turning the cam since the cam has to also adjust the position to follow the rotation its causing jitter

#

but then again idk

glad atlas
#

You're using MoveRotation for a dynamic Rigidbody. AFAIK that breaks the Interpolation setting.

white flax
#

earlier today i followed a tut on third person and even tho i followed it all i still got jitter

#

so i dont even think its my code

#

could u perhaps test my code in ur unity

#

cause i lwk dont think its my code anymore

#

like ive tried everything

#

for 3 days

#

even chat gpt couldnt save me

glad atlas
#

... It's your code dude @white flax

#

I forgot where this screenshot is from but.. yea ...

#

ChatGPT is great at guessing, or summarizing what it found online. Lol 🤷‍♂️

white flax
#

i use move rotation in fixed update RB.MoveRotation(Quaternion.Euler(0,CameraHandler.HorizontalLook,0));

#

the cam is the issue

glad atlas
#

Dude are you reading the post?
It says for non-Kinematic Rigidbody, you will break interpolation if you use MovePosition & MoveRotation

white flax
#

what should i use then

#

cause chaging rotation on the transform didnt fix it either

glad atlas
#

??? It says AddForce and AddTorque righ tthere

#

Yeah you can't, because it's a dynamic Rigidbody ... You're not supposed to directly manipulate them

white flax
#

how am i supposed to add torque or force to rotation when its a quaternion

glad atlas
white flax
#

they didnt

glad atlas
#

I saw you were having movement jitter issues too, to which I am saying all this other stuff.

white flax
#

i only have the rotation jitter on my player

#

but thats from my cam 100%

#

i made a auto rotation system for the player and there was no jitter

glad atlas
#

Good to hear... So let's smooth the HorizontalLook and VerticalLook

white flax
#

how 😄

glad atlas
white flax
glad atlas
#

Yup that's exactly how it is, created from the Euler representation. I hope you're clamping those values already before this line

white flax
#

btw adding smoothing to the player didnt fix the jitter hence why its 100% the cam

transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.Euler(0,CameraHandler.HorizontalLook,0),Time.deltaTime * 10);

glad atlas
white flax
#

correct?

Quaternion TargetRot = Quaternion.Slerp(CamHolder.rotation,Quaternion.Euler(VerticalLook,HorizontalLook,0),-10.0f * Time.deltaTime);

glad atlas
#

You can just Slerp the transform.rotation directly no need to store it again but yea

white flax
#

I thought directly changing pos or rot of the cam is bad thats why i use a cam holder parent

#

that didnt work

glad atlas
#

this HandleCamTransform() looks super funky ... is that AI generated code

white flax
#

no

#

its js my work of 3am and 2 hrs of sleep

#

and hrs of trying random things

#

but i promise its not ai

glad atlas
#

Yeah it's probably "too much" going on honestly

white flax
#

my cam doesnt move at all like rotation

    Quaternion TargetRot = Quaternion.Slerp(CamHolder.rotation,Quaternion.Euler(VerticalLook,HorizontalLook,0),-10.0f * Time.deltaTime);

    CamHolder.position = Player.position - TargetRot * Offset;
    CamHolder.rotation = TargetRot;
glad atlas
#

You didn't copy the 3rd parameter correctly

white flax
#

ohhh

glad atlas
#

just paste in what i sent literally 1 - Mathf.Exp(-10.0f * Time.deltaTime)
you should read the page too, so you understand more

white flax
#

i will read it after i fix this i seriously gotta learn after this cause i used to do 2d

#

ok thats working

#

js gotta fix the 3rd param on the player rot

#

and pray that it works

glad atlas
#

... Player rot? is that using Slerp too?

white flax
#

if u dont mind me asking whats the difference between
Mathf.Exp(-10.0f * Time.deltaTime)
and Time.deltaTime * 10

white flax
#

jitters back btw

glad atlas
#

it's 1 - Mathf.Exp(-10.0f * Time.deltaTime)
it's explained on that page, and further in the Freya video referenced

glad atlas
white flax
#

alr gimme a sec

glad atlas
#

Only when rotating? Moving is OK?

white flax
white flax
glad atlas
white flax
#

ye

glad atlas
#

are you, making the character rotate towards the "camera forward"?

#

By using .MoveRotation ?

white flax
#

nah i showed my code near the end of the vid

#

transform.rotation = Quaternion.Euler(0,CameraHandler.HorizontalLook,0);

glad atlas
#

Okay, great, so that's even worse

white flax
#

i use that as a tempoary way to show the jitter without having to walk

glad atlas
#

You cannot move a Rigidbody like that

#

Are you familiar that Update and FixedUpdate are always out of sync?

#

I recommend you switch on Is Kinematic and use MoveRotation, in FixedUpdate. with Interpolation enabled

white flax
#

this right

#

then this RB.MoveRotation(Quaternion.Euler(0,CameraHandler.HorizontalLook,0));

#

Nope didnt fix the jitter

glad atlas
#

Interpolatation is set to Interpolate on your player Rigidbody?

white flax
white flax
#

I dont think its my code like deadass i dont think its acc my code

#

i think its my unity settings or smthn

#

Thats why i asked u to test my code in ur own unity

#

cause i remember when i was making a first person game i had heavy cam stutter and spent 2 days trying to fix it js for it to not be my code but it was a settings

glad atlas
#

is your Cinemachine camera set to Fixed Update mode? "Smart Update" is usually solid, or LateUpdate.

white flax
glad atlas
white flax
#

but the tutorials dont use cinemachine 😭

glad atlas
#

I use Cinemachine but super configured, like i take control of most things on my own

white flax
#

and i looked at it for 1 second and it was js a thousand different things

glad atlas
#

is the tutorial in Unity 6? usually you can see at the top of their window

white flax
#

i like making everything myself

glad atlas
#

Whatever you're doing with CamHolder.position = Player.position - TargetRot * Offset; seems a lil funky but

glad atlas
#

I look at it and I'm just thinking... What? Why

white flax
#

We'll combine the Camera and the Movement script to get a simple Third Person Controller. You can use this structure as a base for prototyping your ideas.

Next, I am planning to add a 3D character with movement animations.

Contents:
00:00 - Intro
00:21 - Scene Setup
01:18 - Third Person Camera Setup
02:53 - Player Movement Setup
05:38 - Rotate...

▶ Play video

Checkout the full Third Person Parkour System Course here - https://fantaco.de/unity-parkour-system
Get our Advanced Parkour and Climbing System Asset - https://prf.hn/l/y8kYEa4/

Hey everyone, in this video we'll create a Third Person Controller in Unity. We won't be using any assets to build it, we'll build it completely from scratch because ...

▶ Play video
glad atlas
white flax
white flax
glad atlas
#

... Unity 2020
... Unity 2020

white flax
#

is it that much of a big difference tho

glad atlas
#

No offense but these are very uhh bottom tier videos. Maybe slightly better practices used than Code Monkey

#

Sasquatch B is usually quite technical

#

But in the first place they're out dated, from Unity 2020 🤷‍♂️

white flax
#

nvm its fixed now

#

since im using the movedirection

#

js done this

    if (MoveInput == Vector3.zero)
    {
        RB.linearVelocity = new Vector3(0f, RB.linearVelocity.y, 0f);
        return;
    }

    Vector3 FinalDirection = MoveDirection * CurrentSpeed;
    RB.linearVelocity = new Vector3(FinalDirection.x, RB.linearVelocity.y, FinalDirection.z);

    RB.MoveRotation(Quaternion.LookRotation(MoveDirection));
#

but jitter aint gone 😭

glad atlas
#

You're trying to build like 4-5 things at once, so. You're not gonna know what the issue is

#

Maybe remove as much code as you can. Like the linearVelocity stuff.

white flax
#

even when i done this which doesnt involve any movement i got jitter

RB.MoveRotation(Quaternion.Euler(0,CameraHandler.HorizontalLook,0));

#

I rewrote my code over 20 times nothing worked

glad atlas
#

I think MoveRotation needs some Time.deltaTime in there ...

white flax
#

like slerp?

#

Quaternion.LookRotation(MoveDirection * Time.fixedDeltaTime

#

lets see if that works

#

nope its even worse

#

I think my cameras js lagging behind my player when rotating

glad atlas
white flax
#

i dont think so

#

its more of a my camera is lagging

#

from my testing i saw the cam was lagging not the player

glad atlas
#

Can you comment out these 2 functions, see if anything changes.

    {
        HandleMovement();
        HandleJump();
    }```
white flax
#

in scene view everything is fine it looks like both are working

glad atlas
white flax
#

but no jitter like that

glad atlas
#

Just a perfectly smooth camera rotation.

#

Okay

white flax
#

so its 100% the camera thats lagging

#

since the rotation had nothing to do with the cam

glad atlas
#

This post seems to have some relevant info

#

What about if you go into Rigidbody and apply a constant angular velocity?

white flax
#

my wifis kinda ass rn so nothing loads properly

glad atlas
#

No script rotation just in the Rigidbody component inspector

white flax
#

lemme test it rq 1 sec

white flax
glad atlas
white flax
#

oh 😭

#

Godot must be nice if it has that

glad atlas
#

It's alright, very "DIY" almost like you make your own game engine

white flax
glad atlas
#

Tbh I'm not sure anymore what the issue could be. You went down a bit of a strange path Ngl

white flax
#

can u please test in ur unity

glad atlas
#

Especially with the low tier Unity 2020 tutorial videos 🥲

white flax
#

js to make sure its acc my code

glad atlas
#

I doubt anyone on this channel would be willing to do that

#

Maybe upgrade to Unity 6000.2.9 though

white flax
#

im on unity 6

glad atlas
#

You're using an old version, of an experimental version of Unity

#

At least use the latest experimental version which is 6000.2.9

white flax
#

if u could test my code in ur unity to see if its acc my code that would prob let me pin point the issue easier and not waste time

glad atlas
#

Idk go into the Unity Hub and check? I just told you we have 6000.2.9 and actually i see 6000.2.10 now

white flax
#

downloading this

#

oh ye mine is older lol

glad atlas
#

Maybe it has glitches. many people say to only use 6.0, but I found 6.2 runs cleaner

white flax
#

I hope this fixes it 😭 🙏🏼

glad atlas
#

I think they're putting the most work into 6.2 so

#

Yeah if not, well. You have a lot going on dude

#

I had a dynamic Rigidbody player, third person camera as well, never had any issue like this. So...

white flax
#

The thing confusing me the most is the tutorials and the time when i made a first person game and 4 days ago when i was making a 2d game

glad atlas
#

I switched to Character Controller because it's just much easier

white flax
#

no rigidbody?

glad atlas
#

Make sure the tutorials are in Unity 6. And try to determine if the creator is actually using best practices or just "hacking some BS together for a video" like CodeMonkey does

#

LlamAcademy is usually very technical. Look over to the members list, he's on there... Insider status

#

Sasquatch B, git-amend, Beans, GameDevBeyondTheBasics

white flax
#

almost done installing btw

glad atlas
#

Fundamentally what you want is actually quite simply ... But your code, is doing way too much extra weird stuff to reach that goal

white flax
#

how come

#

its not doing anything extra

#

its js rotating the cam and player

glad atlas
#

can you explain what this does then CamHolder.position = Player.position - TargetRot * Offset;

white flax
white flax
glad atlas
#

idk why the cam holder position would need to change
and what's with all the setting rotation to 0 in different places

#

Yeah so... That sounds like a Slerp situation, orbiting in a circle

white flax
#

slerp didnt fix it tho

glad atlas
#

This is overcomplicated, you just need the camera to hard look at some CameraFollow object, and rotate that

white flax
#

i tried smoothing em

glad atlas
#

Yeah because the code is funk dude, like what even is that

#

That's probably breaking the smoothing, it's just taking raw positions & rotations and assigning 🤷‍♂️

white flax
#

Moment of truth

#

ye i still have jitter 💀

glad atlas
#

This is what you want is it not ...

#

Camera orbits around player's chest / neck position smoothly

white flax
#

I have that until the player starts rotating as well

glad atlas
#

It's not what you have dude

#

You have, whatever the heck that code is lol

#

This here, can be accomplished with way less funk & overcomplication

white flax
#

alr so how am i supposed to put the cam behind the player

glad atlas
#

Are you familiar with a SpringArm... It's a common simple way for a camera to "orbit around" the player

white flax
#

im out of ideas

glad atlas
white flax
glad atlas
#

You can put your Camera as child of some "CameraFollow" object.
I assume it always faces the object then right. You place it some distance away I believe Z axis is popular for that.
Now we've created a "SpringArm" kind of setup. (Cinemachine has this built in, in 3 clicks ......)

Then in game, you simply rotate that CameraFollow object. 🤷‍♂️
And also make it follow the Player, or some offset to the player (like at their neck or chest height.)

#

Cinemachine has orbit built in and that kind of stuff but. This would be a basic "Third Person Follow"

white flax
#

im a lil confused

#

it works @glad atlas

#
Quaternion TargetRot = Quaternion.Euler(VerticalLook,Player.eulerAngles.y,0);

        // CamHolder.position = Player.position - TargetRot * Offset;
        CamHolder.rotation = TargetRot;
#

Its not a method ive seen b4 but it kinda works ig

#

wtf is going on

#

erm

glad atlas
#

Well fundamentally it's just, a camera orbiting in a spherical shape around a target

white flax
#

so randomly i start auto rotating

glad atlas
#

Whatever else code you have going on, is overcomplication & clutter

white flax
#

and over time it slows down

glad atlas
#

It's not supposed to be under the Player 😭

#

Hence why i said, it has to follow the Player position or some offset like neck or chest height

white flax
#

but it works 😭

glad atlas
#

Yeah so take it off and it'll stillwork ??

white flax
#

But i feel some stutter

glad atlas
#

It's not supposed to be under the Player it's unrelated lol

white flax
#

so what do i do then

glad atlas
#

In code, you make the CamHandler follow the player

#

Or for now, just take it off the Player and see how it feels to rotate it

white flax
#

btw by doing that i cant look at my character when not moving i was tryna make it like megabonk

#

I took it out of the character

#

float YRot = MovementHandler.MoveInput == Vector3.zero ? HorizontalLook : Player.eulerAngles.y;
Quaternion TargetRot = Quaternion.Euler(VerticalLook,YRot,0);

glad atlas
#

... 💀

white flax
#

😭

glad atlas
#

Can you even explain what that's supposed to do

white flax
#

yes

#

whats confusing abt it

#

breh can u js update my code for me

#

my brain is gone

#

i dont have sleep

#

i cant even talk proper english rn

glad atlas
#

?? Excuse you

white flax
#

bro look at it from my point of view ive been trying to fix this thing for 3 days with under 3 hrs of sleep

glad atlas
#

We all have stories just like that.
Except you're using the most basic "shit code that still works though" tutorials, from an outdated version of Unity, and you refuse to read the Docs or other stuff I've sent

white flax
#

but it was working in 2d

#

and cmon outdated or not they can still work

#

its perfectly logical code

#

I ended up asking chat gpt and even he couldnt do it so i gave up on him

glad atlas
#

... Yeah, that I literally built in my own project, and never had these issues

white flax
#

if chat gpt cant make a proper movement system then its not the code

white flax
glad atlas
#

That's nuts

white flax
#

it was smthn wrong with unity a few months ago

#

also im not relying on chat gpt i tried to see if it could fix it as a last resort

glad atlas
#

Okay if you want, don't do the "spring arm" hack with the parent/child game object trick.
Go and move the camera on your own then, probably Vector3.Slerp will make it possible to smoothly orbit something

white flax
#

isnt that what i done bro

glad atlas
#

And there's still an issue ?

white flax
#

like i dont get it

glad atlas
#

What's the new issue?

white flax
#

not changing position via code

#

and only doing rotation

glad atlas
#

Okay so you moved the CamHolder out of the Player. So its just on its own, its own GameObject in the scene.

#

So the camera rotates fine now? How does it look when the Player moves. I realize we didn't add camera follow yet.

white flax
#

I have jitter

glad atlas
#

You can't just take 10 steps forward in one shot. You didn't validate the previous code, before moving onto new functionality

white flax
glad atlas
#

What is jittering.

white flax
#

Well on the camera it looks like the player is jittering

#

but in scene view everythingggggg is fine

glad atlas
#

When the player moves?

white flax
#

nope

glad atlas
#

in Playmode, if nothing is moving, is there still jitter?

white flax
#

if i turn around

glad atlas
#

Send video this is getting verbose

#

It's not clear what's still the issue thanks

white flax
#

like if im rotating the player based on anything to do with my mouse pos then theres jitter on the player

glad atlas
#

Yeah you probably should be using mouse pointer delta bro

#

Not the raw mouse position

white flax
#

MousePos = InputHandler.GetInput("Look").ReadValue<Vector2>();
HorizontalLook += MousePos.x * NewSensitivy;
HorizontalLook = (HorizontalLook + 360) % 360; // Cap to 360

    VerticalLook -= MousePos.y * (NewSensitivy / 2);
    VerticalLook = Mathf.Clamp(VerticalLook, -MaxY, MaxY); // Limit cam vertical
glad atlas
#

it's called Delta [Pointer] give that a try

#

Why would the raw mouse position be used for this

#

That seems like an early mistake, unless I'm mis understanding

white flax
white flax
glad atlas
#

yeah, switch to Delta [Pointer] ...

white flax
#

whats that 😄

glad atlas
#

You're welcome

#

it's the 4th one

white flax
glad atlas
#

Yeah ... Should be fine

white flax
#

i was already using that 😭

glad atlas
#

try changing the -10 in the Slerp to like, -50

white flax
#

I stopped using slerp cause it didnt change anything 😭

#

what should i put the slerp on

glad atlas
#

... It made the camera rotation smooth as fuck what

white flax
#

the cam rotation
the player rotation
or both

glad atlas
#

You literally sent videos of it easing out of rotation. Looked great

white flax
glad atlas
#

Let's not say "it was jittering" let's use more specific language please

white flax
#

smooth which one

the cam rotation
the player rotation
or both

glad atlas
# white flax

This video. The rotation is perfectly smooth, looks great. Your character was the issue, at this point at least.

#

CamHolder.rotation = Quaternion.Slerp(...);

white flax
#

look at the red part

#

thats to show the players rotation

#

its clearly jittering

#

The camera rotating is fine but the player looks like its jittering cause of the camera

glad atlas
glad atlas
#

Yeah. So the camera has no jitter

white flax
#

how

glad atlas
#

... Your player is jittering not the camera

white flax
#

well ye

#

but the camera is making it look like the players jittering

glad atlas
#

No it's not

white flax
#

all my tests concluded to the camera being the cause

glad atlas
#

The player rotation is making it look jittery, because it is

#

using MoveRotation is its own topic, so. Good luck

#

I recommend you switch to a regular Character Controller ASAP

white flax
#

Look ima do this auto rotate ok

#

transform.rotation *= Quaternion.Euler(0,5,0);

#

and watch what happens

glad atlas
#

Sure, and break Unity interpolation of Rigidbodies

#

Causing jitter

#

basically
RB.MoveRotation(Quaternion.Euler(new Vector3(0.0f, 5.0f, 0.0f) * Time.fixedDeltaTime));

white flax
glad atlas
#

and that goes in FixedUpdate

white flax
#

Only jitters when i move my cam even tho the rotation of the player has nothing to do with the camera or mouse

glad atlas
#

this is with Is Kinematic checked

#

Well it's because the rotation speed of the camera doesn't match the player. So what

white flax
glad atlas
#

And put the code I sent

#

and if it still stutters we can look into that

white flax
#

btw this doesnt rotate at all RB.MoveRotation(Quaternion.Euler(new Vector3(0.0f, 5.0f, 0.0f) * Time.fixedDeltaTime));

#

since its not adding onto the rotation

#

changed to this gonna test now

#

RB.MoveRotation(Quaternion.Euler(new Vector3(0.0f, transform.eulerAngles.y + 5.0f, 0.0f) * Time.fixedDeltaTime));

glad atlas
#

RB.MoveRotation(RB.rotation * Quaternion.Euler(new Vector3(0.0f, 5.0f, 0.0f) * Time.fixedDeltaTime));

#

Yeah well you would've had to read the docs page i sent. Or i would have to be reading it more clearly lol

#

shame about the WiFi

white flax
#

i think its working

#

i dont see jitter

#

tho its very slow XD

glad atlas
#

Sure turn up the speed ...

white flax
#

alr testing again with 20 speed

#

seems fine?

glad atlas
#

Next, change the 5.0f to be, whatever rotation is desired, towards the "target direction" aka camera forward

white flax
#

gonna try 50 now

glad atlas
#

Wow so whaddya know... You just had to stop using tutorials from Unity 2020 and read up on Rigidbody kinematic, dynamic, interpolation

white flax
#

NO JITTER OOO

white flax
#

well still gotta find out how im supposed to add the move direction to it

glad atlas
#

Understand that everything you're doing, is extremely well documented and has been done a million times before

white flax
#

correct?

RB.MoveRotation(RB.rotation * Quaternion.Euler(MoveDirection * Time.fixedDeltaTime));

glad atlas
#

And that 90% of tutorials, are total garbage

white flax
#

ima read docs after my wifi is fixed

glad atlas
#

Well... You might want to use Quaternion LookAt or something

white flax
#

ah fairs

glad atlas
#

Rotations can be tricky since they loop around

white flax
#

RB.MoveRotation(RB.rotation * Quaternion.LookRotation(MoveDirection * Time.fixedDeltaTime));

glad atlas
#

Unity provides excellent Quaternion related stuff so, you never really need to do math or understand them

white flax
#

I just realised something if i try to follow the players rotation with my cam theres a jitter 😭

glad atlas
#

Just have to understand how to use what's provided

white flax
#

NVM

#

it worked

#

like this?

RB.MoveRotation(Quaternion.LookRotation(MoveDirection * Time.fixedDeltaTime));

glad atlas
#

Don't you have to multiply by the RB.rotation as well

white flax
#

cause doing * rotation made me spin like crazy

glad atlas
#

Yeah probably because

#

LookRotation is not a delta value ...

#

MoveRotation takes delta, like, "change in angle"
Not "look at this angle"

white flax
glad atlas
#

All you actually need is "how much to rotate in Y angle this frame", that's all the Player rotation is

white flax
glad atlas
#

How you compute that, is your own journey

glad atlas
white flax
white flax
#

its jittering

glad atlas
#

It's 2 moving objects, worse, rotating objects. 🤷‍♂️

white flax
#

This didnt work at all btw

RB.MoveRotation(RB.rotation * Quaternion.Euler(new Vector3(0.0f, MoveDirection.y, 0.0f) * Time.fixedDeltaTime));

white flax
#

im on this rn

RB.MoveRotation(Quaternion.LookRotation(MoveDirection * Time.fixedDeltaTime));

#

maybe i should do * sensitivity???

#

nope

#

still slower

#

im lost again 😭

glad atlas
#

Maybe, get the difference between the RB current rotation and "desired rotation" (camera forward)
And plug that into the MoveRotation

#

In other words the delta

white flax
#

so rb.rotation - camerahandler.horizontallook?

glad atlas
#

Mm... Remember I said with rotations to use Quaternion as much as possible ...

#

This is not gonna be much fun without the Unity Scripting API (Docs) 😢

white flax
#

horizontal look is what the cam uses for its rotation

glad atlas
#

Quaternion has a lot of functions. You might need to get to know them all, before you know which one is good for this use case!

white flax
#

Fixed FINNALY

Quaternion TargetRot = Quaternion.LookRotation(MoveDirection);
RB.MoveRotation(Quaternion.Slerp(RB.rotation, TargetRot, 15f * Time.fixedDeltaTime));

#

just had to smoothen it

#

15 is the speed btw

glad atlas
#

im well aware

white flax
#

but i think it works now

#

well now i gotta figure out how to make the player move

glad atlas
#

Okay, cool. Don't be afraid to learn the details man, without them you won't know if tutorials are janky or solid

white flax
#

ive always used linear vel = for movement

#

but kinematic doesnt allow that 😭

glad atlas
#

Then you'll be back here with more interesting questions stonks

white flax
#

ig 😭 🙏🏼

glad atlas
#

kinematic is much easier. you just use MovePosition and MoveRotation
it's just a little more complex than Character Controller which comes with more built in useful things

rancid shell
#

Why the slerp on the move rotation? Don't you just give it the angle to rotate to

glad atlas
white flax
#

should i use delta time

#

for move pos

glad atlas
white flax
#

im js so tired my brain is working im sorry gng

#

correct?

    Vector3 FinalDirection = MoveDirection * CurrentSpeed;
    RB.MovePosition(FinalDirection * Time.fixedDeltaTime);
glad atlas
#

Mao is right though, MoveRotation technically sets an absolute rotation instantly

white flax
#

well hell to the no

#

its not working

glad atlas
# white flax its not working

Dude you're gonna be saying "it's not working" every time you change the code, if you don't truly know what it does

#

Yeah of course. Hence "instantly" not "smoothed"

#

as shown in Unity docs, MoveRotation (currentRotation * quaternionDelta * Time.deltaTime) factors in the current rotation too. Instead of setting to an absolute rotation

white flax
#

whats quaterniondelta

glad atlas
#

The difference in angle from current rotation to desired rotation, not an absolute angle

white flax
#

is it a float

#

gonna test it out

glad atlas
#

No it's a Quaternion that's what this function accepts. public void MoveRotation(Quaternion rotation)

white flax
#

I feel stupid af

    Quaternion TargetRot = Quaternion.LookRotation(MoveDirection);
    Quaternion delta = TargetRot - RB.rotation;
    RB.MoveRotation(RB.rotation * delta * Time.fixedDeltaTime);
glad atlas
#

Wanna feel less stupid?

#

Start using Debug.Log or even better OnGUI to show what these values actually are at all times

#

What you want is, to know the difference in angle between your player and your camera

#

Probably can be done with Vector3.Angle or Quaternion.Angle, they behave differently

#

Maybe you should Debug.Log both, see if they're valuable

white flax
#

cant debug this 😭

glad atlas
#

Instead of keep trying to hack this code into working, without doing any extra learning or calculation

shy dome
#

thats called an error, you read the error

#

you cant just subtract quaternions like that

glad atlas
#

Same way you cant just use RB.rotation = (without introducing jitter AKA breaking Unity's physics interpolation)

white flax
#

well i dont know how to get the delta 😭

glad atlas
#

Just told you

#

Probably can be done with Vector3.Angle or Quaternion.Angle, they behave differently
Maybe you should Debug.Log both, see if they're valuable

#

Go ahead and Debug.Log those, comment out the .MoveRotation part so it's not affecting the readings

#

I'll check, how am I even doing "delta Y rotation angle" in my project 🤔

white flax
#

still didnt work

    Quaternion delta = Quaternion.Angle(RB.rotation,TargetRot);
    RB.MoveRotation(RB.rotation * delta * Time.fixedDeltaTime);
glad atlas
#

Oh what do ya know. I'm using Vector3.SignedAngle
lookAngle = Vector3.SignedAngle( ... );

shy dome
#

oh mb i see how you're using it

glad atlas
white flax
#

whats the axis

glad atlas
#

Vector3.up

white flax
#

theres js erros after errors

glad atlas
#

Well you just tried to plug a Quaternion into a Vector3.

#

How about we use the CameraHolder forward?

#

Might wanna strip the Y value first.

#

new Vector3(CamHolder.transform.forward.x, 0.0f, CamHolder.transform.forward.z).normalized, Vector3.up)

#

It probably doesn't need to be normalized. I forgot why i have that there prob unnecessary

white flax
#

im getting more and more confused by the minute

glad atlas
#

So you need two Vector3s, to check the angle between.

#

I just gave you one of them, it's the CamHolder "forward" which is a Vector3 pointing in the... forward direction of the GameObject

#

Now put in the RB.transform.forward or something, and you can Debug.Log out the angle between.

#

Same thing, get rid of the Y value by creating a new Vector3 and just.. not keeping the Y value lol

white flax
glad atlas
#

You didn't even send the whole line of code

white flax
glad atlas
#

Dude the function takes three Vector3s ... Like...

white flax
#

its what u sent me
Vector3 cam = new Vector3(CameraHandler.CamHolder.transform.forward.x, 0.0f, CameraHandler.CamHolder.transform.forward.z).normalized, Vector3.up);

#

i was doing it seperatly cause it got too long i couldnt read it

glad atlas
#

yeah so.. no Vector3.up there

#

vector3.up is the third paramter of the SignedAngle function bro

#

😂

white flax
#

never mind

#

im stupid

glad atlas
#

.normalized goes outside the parenthesis

white flax
#

i thought u was sending it as seperate

glad atlas
#

it's ok, sleep deprived code writing leads to this

#

yeah so

white flax
#

this?

Vector3 cam = new Vector3(CameraHandler.CamHolder.transform.forward.x, 0.0f, CameraHandler.CamHolder.transform.forward.z);

glad atlas
#

Sure ... Now the same thing for the rigidbody.transform.forward

#

Then plug them into Vector3.SignedAngle(camForward, rbForward, Vector3.up);

white flax
#
        Vector3 cam = new Vector3(CameraHandler.CamHolder.transform.forward.x, 0.0f, CameraHandler.CamHolder.transform.forward.z);
        Vector3 rb = new Vector3(transform.forward.x,0,transform.forward.z);
        Quaternion delta = Vector3.SignedAngle(rb,cam,Vector3.up);
glad atlas
#

Sure so log out that delta, see if the values seem legit ...

white flax
#

js a small issue 😄

glad atlas
#

Even better put it on the GUI... (has to be moved out of the function)

#

Mhm ... Prob can't use floats there ...

white flax
#

but there arent any floats there

#

both are vector 3

glad atlas
#

... I can't see the code behind the error sir

glad atlas
#

Yo i cant see the code like ... I dont need the error i need the code

#

I'll tell u if there's an error i dont need red underline

shy dome
#

that is not valid c#

white flax
#

i already send it

glad atlas
#

float delta ...

#

Did u know, Vector3.SignedAngle returns, a float ...

white flax
#

so it had to be a float

#

😭

glad atlas
#

Debug.Log(delta); see if that gets you what you need

white flax
#

proof that im truly sleep deprived i cant keep my eyes open rn

shy dome
#

you should really take a step back and actually understand what you're writing before trying to get into all of this. being spoonfed this (whatever this is) clearly isn't getting you anywhere.
and just to let you know, this isnt gonna change anything about your actual issue. Rotating by calculating with quaternions vs using floats/euler angles is still going to rotate the same amount here

white flax
glad atlas
#

Wanna really flex...
use Debug.DrawRay to show your character forward, camera forward... always helpful to visualize

white flax
#

I think it worked

125.7
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

123.9
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

121.8
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

115.7
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

112
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

107.2
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

103.4
UnityEngine.Debug:Log (object)
MovementHandler:HandleMovement () (at Assets/Scripts/Movement/MovementHandler.cs:107)
MovementHandler:FixedUpdate () (at Assets/Scripts/Movement/MovementHandler.cs:44)

glad atlas
#

Okay cool ... Does that seem like, the actual angle between the rotations

#

In other words, when facing the same direction as player, it would be approx 0.

white flax
#

yep it works its sending the distance between both rots

glad atlas
#

So when facing same direction, 0.
Opposite directions, closer to -180 or 180 whatever.

shy dome
#

How have we progressed backwards here? It was mentioned already 1-2 days ago that the issue isn't with the actual individual object jittering. It is simple an issue between the camera and object updating at different times

white flax
#

we progressed forwards the jitter is kinda gone

#

js let @glad atlas cook he saved me gng

shy dome
#

It was equally gone yesterday from a video you had that looked the same as one above

#

you can calculate the rotation 100 different ways if you want and achieve the same result. This isnt going to change the actual underlying error

glad atlas
#

I don't think he has an error anymore? Or

white flax
#

i dont have any errors ig

#

Debug.DrawRay(transform.position,transform.forward);
Debug.DrawRay(CameraHandler.CamHolder.position,CameraHandler.CamHolder.forward);

shy dome
#

error being the jitter, not a compile error.

#

"the jitter is kinda gone" means its still there

glad atlas
#

I think he's referring to the rotating cylinder attached to the player. Right?

white flax
#

on the cam ray the lines pointed at me

white flax
glad atlas
#

That is not "jittering", that's "object rotating at different speed than camera while trying to follow camera's rotation"

#

If that's the only issue, that's not a Unity issue. It's just physics

white flax
#

i have the fixed code but it was a bad method so hes helping me use a better method

glad atlas
#

like in the Interstellar movie where he has to rotate the spaceship to match the spinning one?

#

An object rotating around another a rotating camera, probably will jitter no matter what, if they rotate at diff speeds 🤔

shy dome
white flax
#
 float delta = Vector3.SignedAngle(cam,rb,Vector3.up);
        Debug.DrawRay(transform.position,transform.forward);
        Debug.DrawRay(CameraHandler.CamHolder.position,CameraHandler.CamHolder.forward);
        RB.MoveRotation(RB.rotation * delta * Time.fixedDeltaTime);
glad atlas
mild warren
#

Interpolation doesn't work with kinematic RBs.

shy dome
glad atlas
glad atlas
#

We learned a lot here, and fixed a lot of other stuff that was incorrect

white flax
#

@shy dome @mild warren Can yall js let us fix this like i have a working version if u want proof i can send it

glad atlas
#

So your camera rotates at 10 speed, the cylinder rotates at 5 speed.
And it's supposed to look smooth? Enlighten me how that is possible @shy dome @mild warren

white flax
shy dome
glad atlas
#

Oh shit. That actually looks really good

white flax
#

its not perfect tho

mild warren
white flax
#

theres still some lag cause low speed

#

can we fix this now 😄

glad atlas
shy dome
glad atlas
mild warren
glad atlas
glad atlas
white flax
#

am i dumb 😭

glad atlas
mild warren
glad atlas
white flax
#

@mild warren @shy dome you guys havent been here the whole time ok u havent seen the older code the older videos etc

glad atlas
#

Then remove the outside multiplcation by it

white flax
#

like this?

float delta = Vector3.SignedAngle(cam,rb,Vector3.up) * Time.deltaTime;

mild warren
#

Alright. I guess I'll leave it to you then.

glad atlas
#

Gotcha this resource must be wrong then

mild warren
white flax
glad atlas
#

Well yeah but, you can just do it in the new Vector3

#

Only have to change that same line dude

white flax
#

this?

RB.MoveRotation(RB.rotation * Quaternion.Euler(new Vector3(0.0f, delta * Time.deltaTime, 0.0f)) * Time.fixedDeltaTime);

glad atlas
#

Literally move the * Time.deltaTime inside of the Vector3

#

Yea so get rid of the 2n done

#

Only the inner one

white flax
#

OHHH

#

alr ima test it now

shy dome
white flax
#

NVM

glad atlas
#

@shy dome @mild warren

#

from Unity doc page

white flax
#

I done it the wrong way around

glad atlas
#

What are you guys on about? Respectfully

mild warren
glad atlas
#

We can use MoveRotation for Dynamic RBs???

mild warren
#

Yes

glad atlas
# mild warren Yes

Well thanks I'll be giving that a shot. I discontinued my dynamic Rigidbody controller because [I thought] AddForce and AddTorque were required unless kinematic.

mild warren
#

Kinematic bypass force and velocity calculations in physics.. MoveX set the internal state of the rb directly.

glad atlas
#

@white flax if you switch off the Is Kinematic, does the MoveRotation still work the same?

#

Let's just find out now eh? Before I go busting out my old Dynamic RB character code.

white flax
glad atlas
white flax
white flax
glad atlas
white flax
#

idk it looks laggy

#

ima send a vid wait

glad atlas
#

Hmm, okay. @mild warren any comments

mild warren
#

I don't even know what the aetup/code looks like now.

white flax
mild warren
#

I'm not gonna read 150 messages.

white flax
#

u dont have too evidenece is here

glad atlas
#

We're just testing if MoveRotation works fine with a Dynamic RB.

#

Well it seems fine, seems smooth. Idk why i concluded before that those functions don't work for Dynamic RBs.

white flax
glad atlas
#

@white flax it's teleporting because of the movement code, the rotation itself seems fine. A little slower i guess

#

Unless @mild warren is wrong about dynamic RBs

mild warren
#

Yes, as I said, move rotation does work with dynamic. I'm not entirely sure if they comply with interpolation.

glad atlas
#

Yea uh... Pretty sure they don't ...

#

This whole talk was about, how to move RBs of both types, without breaking Unity's interpolation

white flax
#
        Vector3 cam = new Vector3(CameraHandler.CamHolder.transform.forward.x, 0.0f, CameraHandler.CamHolder.transform.forward.z);
        Vector3 rb = new Vector3(transform.forward.x,0,transform.forward.z);
        float delta = Vector3.SignedAngle(rb,cam,Vector3.up);
        RB.MoveRotation(RB.rotation * Quaternion.Euler(new Vector3(0.0f, delta * Time.deltaTime, 0.0f)));

so uhm how do i increase the speed doing delta * 5 made it jitter like crazy

mild warren
#

MoveX is kinda poorly documented. Especially in regard to dynamic/kinematic. I'd just use angular velocity with dynamic.

#

Or interpolatie manually with kinematic(in update).

glad atlas
#

I can bust out my old RB character and try it but. Pretty sure you break interpolation of a Dynamic RB using anything but AddForce / AddTorque

mild warren
#

I did mention MoveRotation yesterday, which is my bad. I usually avoid it.

shy dome
#

the only real questionable part I find with move rotation is stuff like friction or well just anything that'd actually stop the rotation. For most games you really dont need objects to actually hit each other by rotating around so ignoring physics is fine

glad atlas
#

yeah i meant MovePosition and MoveRotation.

#

So next time, you guys can call me the expert OK?

#

😉

white flax
glad atlas
shy dome
#

Also do you have a physics material on the character?

glad atlas
#

Go a step further and have you entire Player Config related stuff as a Scriptable Object. Retains after play mode lol unlike Inspector

shy dome
#

friction might be slowing it down but i forgot honestly how that applies here. I never really use friction

white flax
glad atlas
#

I was jk this whole time btw. digiholic is the only expert uwu

#

cheers guys cya next time

white flax
#

are u going?

#

tysm bro like fr tysm u spent 3 hrs helping me tysm i can finnaly work on my game instead of fixing a bug 😭 🙏🏼

#

I kinda cant jump btw i done add force but nothing

glad atlas
#

@mild warren @shy dome i was jk around btw guys, friends still? 🤝 Unity

#

No prob, just know that most people here will just send you a link or two and say "read the docs, figure it out"

#

I know it can be daunting because i spent months experimenting with all this stuff. And it was miserable

white flax
#

my eyes are burning

#

like im saying oven burning

#

im tearing up XD

glad atlas
#

Yeah try not to sacrifice yourself for the game

white flax
#

its cause i have a shit ton of hw

#

and i js quit my 2d game 4 days ago

glad atlas
#

Slow & steady, lots of research, "is this the right way to reach my desired result?"

#

Never sacrifice your health or well being for the game. Games take a lot of time.

white flax
#

making games is the only thing that cures my depression ive been through alot this year and making games helped aton

mild warren
white flax
#
        Vector3 FinalDirection = MoveDirection * CurrentSpeed;
        RB.MovePosition(RB.position + FinalDirection * Time.fixedDeltaTime);

        Vector3 CamDir = new Vector3(CameraHandler.CamHolder.transform.forward.x, 0.0f, CameraHandler.CamHolder.transform.forward.z);
        Vector3 RbDir = new Vector3(transform.forward.x,0,transform.forward.z);
        float Delta = Vector3.SignedAngle(RbDir, CamDir, Vector3.up);
        Quaternion DeltaRotation = Quaternion.Euler(new Vector3(0.0f, Delta * RotationSpeed * Time.deltaTime, 0.0f));
        RB.MoveRotation(RB.rotation * DeltaRotation);
#

this is wrong right?

RB.AddForce(Vector3.up * JumpPower,ForceMode.Impulse);
#

it prints jumped but doesnt jump

shy dome
#

that should be fine, if you aren't jumping then check your jump power or see if you are directly overwriting velocity elsewhere

white flax
#

even when i set it too 100 jump power it doesnt owrk

mild warren
white flax
#

ye

#

fixed update

mild warren
#

And a kinematic RB?

white flax
#

ye

#

@glad atlas hehehe whats going on 😄

shy dome
#

A kinematic rb isnt going to respond to forces

mild warren
white flax
white flax
shy dome
#

either dont make it kinematic, or you'll need to move it via its position (or move position) and manually calculate collisions

#

but i thought u didnt have it kinematic for the rotation stuff like minutes ago

white flax
#

i did

#

kinematic is the only reason why its not jittering

#

but ig it has its cons

mild warren
#

Yeah, I still don't believe interpolation works with a kinematic RB... 🤔

white flax
#

thats gonna make everything so hard

#

i have to change the pos each time js to add a force

#

wait how do i check collisions

#

😭

shy dome
#

🤔 but you had it as kinematic before, and changed it to non kinematic

mild warren
#

If you use a dynamic rb with forces and velocity, you don't need to worry about collisions.
If it's kinematic you have to do everything yourself.

glad atlas
white flax
#

@glad atlas U didnt warn me abt this 😭 I can walk through things i cant jump

glad atlas
#

Kinematic has its own complexities.
I told you Character Controller is the easiest. And it's what I use

white flax
#

should i js use that then

#

how 😄

glad atlas
#

Dynamic will be fully simulated in the Physics world, but I'm pretty sure MovePosition and MoveRotation don't keep the interpolation with a Dynamic RB.

white flax
#

no rigidbody right

#

for char controller

glad atlas
#

it's the Character Controller component. Much easier to move and rotate all that.

#

No Rigidbody.

mild warren
glad atlas
#

if you need interaction with Rigidbody, it's actually quite simple ...

white flax
#

what now

#

with a char controller how do i add jump pads and allat if theres no rigidbody

glad atlas
#

Like you can have a Character Controller jump through a stack of rigidbody boxes, no problem. Just requires a lil code maybe 10 lines of code.

shy dome
glad atlas
white flax
#

😭 I just want a working walk and cam system why is everything so complicated now days

shy dome
#

if using a character controller, you would usually need a RB anyways in the future to get physics messages. it would have to be kinematic

glad atlas
shy dome
#

🤷‍♂️ what do you really expect, this is game development where you can make anything that you have the ability to code. you need to learn if you want to make something

#

people dedicate decades doing this

glad atlas
#

Yeah, if anything we have to be thankful that Unity provides all the great stuff it provides.

#

@white flax just learn the rules of how to do things! Character Controller is easier than what we just did.

#

It even auto computes if the character is on the ground or not, if you use the functions provided [correctly]

white flax
glad atlas
#

Ok actually gotta go now. Cya good luck!

white flax
#

TYSM CYA

white flax
glad atlas
#

You can always download some of the free "Rigidbody Character Controller" from UnityAssetStore and check out their code thinksmart

white flax
#

@glad atlas

#

Im remaking the whole system cause character controller is too limited i need physics based rigidbody movement

glad atlas
#

Typically you're not supposed to re-tag specific people but hello

white flax
#

but even with the rotation system and kinematic im getting jitter 💀

#

but i found a way to fix it

#

is it safe

glad atlas
#

Remember there is only "the right way" bro

white flax
#

loading the image

glad atlas
#

Nahhh... You broke the interpolation again then

#

Nobody is gonna be able to run your game with Physics happening that often

white flax
#

but it looks fine no jitter

#

oh laggy?

glad atlas
#

Yeah ... Leave it at 0.02

white flax
#

well how am i supposed to fix it now

#

cause the method for rotation from yesterday didnt owrk

glad atlas
#

Read your own code and find out what's off

white flax
#

so i ended making a simple method

white flax
glad atlas
#

It's not rocket science you need to learn the right way to do things

#

There's specific ways to rotate a GameObject smoothly, or a kinematic RB, or a dynamic RB. All different

white flax
#

it js doesnt work tho

#

yesterday our method was working

#

but i made a new project and now it doesnt work

#

----------------------------------------------------------------------------------------------------------------------------------------------------------------------Player rotates at 10.22, 10.24, 10.26, … (exact 0.02s steps = FixedUpdate). Camera updates at 10.2275, 10.2435, 10.2611, 10.2776, … (irregular ~0.016–0.017s = render/LateUpdate). You’ve got multiple camera frames between each physics step. That means the cam keeps easing toward a target that only changes every 0.02s → visible snap/hold/snap = jitter.

glad atlas
#

Again, the player rotation and camera rotation are unrelated.
The player "chases" the camera forward, in FixedUpdate, with appropriate functions that won't break interpolation
The interpolation then renders the "in between" frames in Update, which happens at its own rate.

#

So u want a dynamic Rigidbody character, with a third person follow camera like Megabonk has (literally just a basic TPP orbit)

#

@white flax what's with the overcomplications? Are u doing funky stuff in the code

#

Here's a few CCs from the UnityAssetStore ... Maybe read their code & see how they achieve their results stonks Unity

white flax
#

@glad atlas Im a genius

#

I made a smart af system and it fixed the jitter completly

#

ofc ima keep improving it

#

but still

#

also i had to change time stamp to 0.0167777 cause 60hz

glad atlas
#

It’s not genius at all. The game will be out of sync because render framerate is variable.

#

The point of fixed time is that it is out of sync. Now, do you think your game can run on a 120 Hz or 144 Hz monitor?
Or will you have to cut the time step in half again?

#

🤷‍♂️

white flax
white flax
glad atlas
#

You can switch your Physics system to work on Update if you want. But it is non deterministic & yields unreliable results
Which is why Fixed Time is so important

white flax
#

it was the only fix i could use

#

i tried everything

#

it was the only thing that helped fix the issue and made my system to avoid jitter 10 times better

mild warren
white flax
#

Im gonna make a first person game instead

#

Third person is too much work

#

And i was gonna do parkour but third person parkour aint nice

white flax