Search Unity

Question CinemachineFreeLook Jitters/Deforms during Movement.

Discussion in 'Cinemachine' started by Corza, Apr 21, 2023.

  1. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Cinemachinefreelook Jitter/Deforms during Rotation

    Hi, I've been having a ton of trouble getting cinemachinefreelook to work with my movement and rotation. I am trying to make a simple platformer and my rotation speed seems to be messed up in turn with my camera rotation. I am using the new unity input system and posting a visual of it, before the square deforms it was jittering and I don't know the right combo of settings to get this to work smoothly.

    Simply put I want the camera to be rotatable and the player to rotate on their own too with it all being smooth.

    ​

    My movement code is inside FixedUpdate():
    Code (CSharp):
    1. private void Move()
    2.         {
    3.             Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    4.             Vector3 cameraForward = Camera.main.transform.forward;
    5.             cameraForward.y = 0;
    6.             cameraForward.Normalize();
    7.             Vector3 cameraRight = Camera.main.transform.right;
    8.             cameraRight.y = 0;
    9.             cameraRight.Normalize();
    10.  
    11.             Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    12.             rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);
    13.  
    14.             if (desiredDirection != Vector3.zero)
    15.             {
    16.                 Quaternion targetRotation = Quaternion.LookRotation(desiredDirection, Vector3.up);
    17.                 rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
    18.             }
    19.         }
    could anyone help with this who may have used this component before?

    [Jitter]


    [CinemachineFreeLook]

    [Player Gameobject]

    [MainCamera]

    I have tried many types of settings and no setup works.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    It could be your binding mode. You've got it locked to the target so that means the camera will rotate with the target. Try using World Space binding mode instead.

    upload_2023-4-21_7-44-39.png
     
  3. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    I've actually tried a bunch of binding modes and started with simple follow world up. The only thing that seemed to work was turning AIM to none but then the camera would not look at the player.

    It actually got better when I turned my player rotate speed variable to match similar to the camera rotate speed so I assumed maybe its something to do with the camera lagging behind or an issue with the unity cinemachine input.

    I've tried a lot of options and nothing really works so I can tell you all of the ones I have attempted, from changing the brain updates, to the binding mode, to the dampening, rigidbody interp... and so on. But it seems like such a simple thing?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    If I understand correctly, you want to decouple player rotation and camera rotation, One set of controls to rotate the payer, another set to rotate the camera. You want user input to be relative to camera, so move forward will make the player walk in the direction that the camera is pointing. Is that right?

    If so, then WorldSpace and SimpleFollow are the only options for BindingMode. All the others will couple the rotations. There is no reason that the rotations should get mixed up. Can you show your scene hierarchy? Maybe you have a parenting issue.

    Have a look at the Free Look character sample scene that ships with CM. It's doing what you're looking for, I think
     
  5. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Yes so Ill better explain my expected logic. Moving forward will walk the player where the camera is going, turning left/right will turn the player/player model in that direction. Using the mouse or other control stick will rotate the camera around the player.

    I have tried worldspace/simplefollow as well. I cannot show the scenespace right now but I can provide a link to my repository for this project: https://github.com/Ceruin/Mischief-Makers-Legends

    I did try looking at the Third Person Unity default and copying some of those features but it seems they do not use the cinemachine input for rotating the camera nor do they use rigidbodys.

    "Have a look at the Free Look character sample scene that ships with CM. It's doing what you're looking for, I think"
    I can try that as well but its so odd the jitter always occurs.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Let's put jitter issues aside for now, because there are many possible causes for jitter. First we have to get the basic movement right. To do that, you have to stop changing random things, and start with a basic setup that is correct. Please refer to the Free look character sample and set your camera up the same way.
     
  7. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Ok, I won't be able to work on this again until later tonight. Could you point to me where I would find the Cinemachinefreelook sample, should I already have it?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
  9. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Thanks for the help so far, I will get back to you on if it works or not later tonight.
     
  10. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    So I opened it up after importing and literally copy pasted a few things.
    I still run into this problem which is wild.

    My Active setup:
    upload_2023-4-21_20-0-44.png upload_2023-4-21_20-0-52.png

    Code (CSharp):
    1.     private void FixedUpdate()
    2.     {
    3.         Move();
    4.     }
    5.  
    6.    private void Move()
    7.     {
    8.         Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    9.         Vector3 cameraForward = Camera.main.transform.forward;
    10.         cameraForward.y = 0;
    11.         cameraForward.Normalize();
    12.         Vector3 cameraRight = Camera.main.transform.right;
    13.         cameraRight.y = 0;
    14.         cameraRight.Normalize();
    15.  
    16.         Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    17.         rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);
    18.  
    19.         if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
    20.         {
    21.             //Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
    22.             //rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
    23.             //rb.MoveRotation(Quaternion.LookRotation(desiredDirection));
    24.  
    25.             Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
    26.             var diferenceRotation = targetRotation.eulerAngles.y - transform.eulerAngles.y;
    27.             var eulerY = transform.eulerAngles.y;
    28.  
    29.             if (diferenceRotation < 0 || diferenceRotation > 0) eulerY = targetRotation.eulerAngles.y;
    30.             var euler = new Vector3(0, eulerY, 0);
    31.  
    32.             transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(euler), turnSpeed * rotationSpeed * Time.deltaTime);
    33.         }
    34.     }
    upload_2023-4-21_20-3-26.png
    Example:
    upload_2023-4-21_20-4-4.gif
     

    Attached Files:

  11. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    I am still having this issue. Should I just redo my project?
     
  12. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    189
    Heyyoo :)
    You are moving your cube in fixed update. If you change the update method to fixed update on your Cinemachine brain does you still see the jitter?
     
  13. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Yes I still see the jitter, it's more of a stutter now but yeah.
     
  14. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    here is the visual:
    upload_2023-4-22_21-51-53.gif
     
  15. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    problem still occuring.
     
  16. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    In the Time settings of the Project Settings, there's a Fixed TimeStep value:

    https://docs.unity3d.com/Manual/class-TimeManager.html

    This defaults to 0.02 (1/50), and has done forever. And is far and away one of the most retarding things in all of Unity's defaults. It'll trip you up in all sorts of ways if left at this value and you're working with physics.

    Initially, set this to double your desired frame rate: ie if you're aiming for 60fps, set this value to 1/120 = 0.00833333

    And now see if all the woes of your physics vs your fixedStep updating of Cinemachine have resolved.

    If they have, try backing off the setting to the same as the frame rate: 1/60 = 0.0166666 or thereabouts.

    There are all sorts of other little problems with time and ticks in the Unity engine. But hopefully none of them should appear for something as basic as this. By way of example, if you sample how many times fixedUpdate is called versus the amount of time passed, it's inconsistently inconsistent, even in the newer "fixed" versions of Unity.
     
  17. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    This actually did seem to help a lot! there are some issues still and some questions. Then how do you make a physics based game in Unity with variable framerate. Does this setting have to be adjusted based on a max framerate setting?

    I also get it very slightly stuttering still but it does seem to greatly change things. Do you know why the stutter might have improved but still be there? Do I need to lock the framerate?
     
  18. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    try setting the CM Brain back to LateUpdate.

    If that doesn't fully fix things now physics timestep is more sensible, I'll have to have a ponder.
     
    Corza likes this.
  19. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    So I tried this and changed some of my code back from the cinemachine sample the others had me try. I now use LateUpdate on the brain. Interpolote for the Rigidbody, World space for my cinemachine with aim on composer and my FixedUpdate movement/rotation code:
    Code (CSharp):
    1.     private void Move()
    2.     {
    3.         Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    4.         Vector3 cameraForward = Camera.main.transform.forward;
    5.         cameraForward.y = 0;
    6.         cameraForward.Normalize();
    7.         Vector3 cameraRight = Camera.main.transform.right;
    8.         cameraRight.y = 0;
    9.         cameraRight.Normalize();
    10.  
    11.         Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    12.         rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);
    13.  
    14.         if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
    15.         {
    16.             Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
    17.             rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
    18.         }
    19.     }
    20.  
    Overall this seems to work a lot better. I don't really see jitter, I do see FPS drops but maybe that's only in editor sometimes(?).

    Here is a visual sample to make sure i'm not crazy lol. It looks like the char still trys to turn some but not really jitter nor stutter?:
    upload_2023-4-23_23-55-2.gif
     
  20. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Ok so the in-game when built is fairly bad. It stutters hard
    upload_2023-4-23_23-57-57.gif
     
  21. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
  22. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Agreed! Getting physics to "just work" in Unity is a right royal pain in the places the sun doesn't shine.

    I'll have a look at it later... but, first, for Gregory's checkings... which Unity Editor version and CM version do you have?

    And Windows or Mac?
     
    Corza likes this.
  23. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Windows. I'll have to check Unity/CM version when I get home. I got the CM package fresh so it should be latest but my unity is slightly out of date.
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I had a look at your project (thanks for the upload). For me, it's perfectly smooth if I enable Interpolation on the player. I think you may have forgotten to save that when you made your build.
     
    antoinecharton likes this.
  25. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    upload_2023-4-24_19-30-11.gif
    so i put it on I will update the repo with interp. Still get this issue.
    upload_2023-4-24_19-32-20.png
     
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    This rotational jitter of the target is unrelated to Cinemachine. If I remove Cinemachine from your scene and put this simple LookAt behaviour on the main camera, the problem persists.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class HardLookAt : MonoBehaviour
    4. {
    5.     public Transform Target;
    6.  
    7.     void Update()
    8.     {
    9.         transform.rotation = Quaternion.LookRotation(Target.position - transform.position);
    10.     }
    11. }
    12.  
    The jitter seems to be proportional to the physics step size: a longer physics frame increases the jitter, shorter timesteps hide it. Unfortunately you can't keep shrinking the physics timestep without running into performance barriers.

    My guess is that the problem lies in your Move() code. Because you're manually setting rb.velocity, the resultant movement is nonphysical so the simulation is unable to interpolate the rotations perfectly. That's just a guess (I'm not a physics expert). What happens if you try moving the target exclusively with rb.AddForce and friends, to preserve the integrity of the simulation?
     
    Last edited: Apr 25, 2023
    antoinecharton and Kreshi like this.
  27. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Code (CSharp):
    1. private void Move()
    2.     {
    3.         Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    4.         Vector3 cameraForward = Camera.main.transform.forward;
    5.         cameraForward.y = 0;
    6.         cameraForward.Normalize();
    7.         Vector3 cameraRight = Camera.main.transform.right;
    8.         cameraRight.y = 0;
    9.         cameraRight.Normalize();
    10.  
    11.         Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    12.         Vector3 force = desiredDirection * moveSpeed;
    13.  
    14.         // Calculate the force to be applied
    15.         Vector3 forceToApply = force - rb.velocity;
    16.         forceToApply.y = 0;
    17.  
    18.         // Apply the force to the Rigidbody
    19.         rb.AddForce(forceToApply, ForceMode.VelocityChange);
    20.  
    21.         // Update the rotation
    22.         if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
    23.         {
    24.             Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
    25.             rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
    26.         }
    27.     }
    New movement code above.

    Visual of what happens:
    upload_2023-4-25_19-45-14.gif
    still the slight weirdness. going to push the new code.
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Great, will take a look tomorrow. I'm suspecting that rb.MoveRotation should be replaced as well with force-based calls. What happens if you try that?
     
    antoinecharton likes this.
  29. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    I tried this a bit. I assume you meant using AddTorque. My first attempts didn't seem to work well but I'm also not great with physics here.
    upload_2023-4-26_0-49-23.gif
    I don't think my code for this is very good:

    Code (CSharp):
    1.  private void Move()
    2.     {
    3.         Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    4.         rb.angularDrag = angularDamping;
    5.  
    6.         Vector3 cameraForward = Camera.main.transform.forward;
    7.         cameraForward.y = 0;
    8.         cameraForward.Normalize();
    9.         Vector3 cameraRight = Camera.main.transform.right;
    10.         cameraRight.y = 0;
    11.         cameraRight.Normalize();
    12.  
    13.         Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    14.         Vector3 force = desiredDirection * moveSpeed;
    15.  
    16.         // Calculate the force to be applied
    17.         Vector3 forceToApply = force - rb.velocity;
    18.         forceToApply.y = 0;
    19.  
    20.         // Apply the force to the Rigidbody
    21.         rb.AddForce(forceToApply, ForceMode.VelocityChange);
    22.  
    23.         // Update the rotation
    24.         if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
    25.         {
    26.             Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
    27.             Quaternion deltaRotation = targetRotation * Quaternion.Inverse(rb.rotation);
    28.  
    29.             float angle;
    30.             Vector3 axis;
    31.             deltaRotation.ToAngleAxis(out angle, out axis);
    32.             if (angle > 180)
    33.             {
    34.                 angle -= 360;
    35.             }
    36.  
    37.             Vector3 torque = angle * axis * rotationSpeed;
    38.             rb.AddTorque(torque, ForceMode.VelocityChange);
    39.         }
    40.     }
    repo is updated.
     

    Attached Files:

  30. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Can you describe what you're trying to achieve in terms of feel?
     
  31. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    My goal is to make a 3d platformer, the idea is that the player can move forward and turn while moving. They can also rotate the camera around the player while turning. Like an old Megaman Legends style movement with better Mario Odyssey style in there.
     
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I tried also to make this work, but hit a wall. It might be an issue with physics interpolation. I'll try to get the physics team to look at this.

    I was able to make a simple scene of a cube orbiting a fixed camera, and the cube's rotation is jittery when interpolation is enabled. It smells like a physics bug to me.

    EDIT: Not a physics bug. See below for an explanation of what's happening.

    PhysicsRotationJitter.gif
     

    Attached Files:

    Last edited: Apr 27, 2023
    Corza and antoinecharton like this.
  33. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Thank you so much for looking into this. I guess my best bet would be to wait for now then and maybe try another game idea in the mean time?

    Is it possible to update me or this thread when it gets fixed if it is a bug.
     
  34. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Or you could go ahead with your game idea, and just live with the minor jitter until the issue gets fixed. You can mitigate it to some extent by reducing the physics step size.
     
  35. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Ok, yeah that sounds good too. Maybe I can mask it somehow or it won't annoy me much lol.
     
  36. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    When I tried your project earlier with a reduced physics step size, it looked pretty smooth to me. Also, maybe find a player geometry that's a little more forgiving of minor rotational inaccuracies (a sphere, perhaps? lol)
     
    Corza likes this.
  37. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    I can try reducing the physics step size and seeing. I love cubes so much lol, they're easy to work with when all i'm good at is voxel art. It will likely not be as bad once I have real assets to work with.

    Thank you all so much again, glad going crazy over this is pushed off to the dev team now lmao.
     
  38. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    @Corza It seems that I misled you with all that AddForce stuff. This Move code gives smooth results, even with the default 0.02 physics time step. RB.angularVelocity seems to be the missing piece.

    Code (CSharp):
    1.     private void Move()
    2.     {
    3.         Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
    4.         rb.angularDrag = angularDamping;
    5.  
    6.         Vector3 cameraForward = Camera.main.transform.forward;
    7.         cameraForward.y = 0;
    8.         cameraForward.Normalize();
    9.         Vector3 cameraRight = Camera.main.transform.right;
    10.         cameraRight.y = 0;
    11.         cameraRight.Normalize();
    12.  
    13.         Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
    14.         rb.velocity = desiredDirection * moveSpeed;
    15.  
    16.         // Update the rotation
    17.         if (desiredDirection.magnitude > 0.1f)
    18.         {
    19.             var angle = Vector3.SignedAngle(rb.rotation * Vector3.forward, desiredDirection, Vector3.up) * Mathf.Deg2Rad / Time.deltaTime;
    20.             rb.angularVelocity = Vector3.up * angle;
    21.         }
    22.     }
    Make sure you unfreeze the rotation constraints.

    upload_2023-4-26_16-26-45.png
     
  39. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Few things. I copied this and my results are odd.
    upload_2023-4-26_17-51-45.gif
    I think I must have something else different, it doesn't rotate but I followed your steps. also committed these changes to my repo to see.

    second when you multiply for the angle should you not use Time.FixedDeltaTime if your keeping it in the fixedupdate or is this now in update?
     
  40. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Probably your rotations are frozen, or you have a big number in angular drag. As for fixedDeltaTime, yes you're right, but unity does this thing of assigning deltaTime = fixedDeltaTime during the FixedUpdate call, so it works out to the same thing.
     
    Last edited: Apr 27, 2023
  41. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Ok that fixed it. It works fairly well, gravity is super high and I can't jump but I assume those are easy fixes.
    And yes the issue was my angular drag.

    Thank you.
     
    Gregoryl likes this.
  42. Corza

    Corza

    Joined:
    Jun 10, 2016
    Posts:
    25
    Also it seems deleted but to whoever suggested unreal, it does seem like a decent option but I far prefer unity. my comfort is here and it reminds me a lot of other tools like Hammer. c# is also very nice.
     
  43. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Just circling back here. It's not a physics bug. In fact Rigidbody.MoveRotation bypasses interpolation so what was happening was that the position was being interpolated, but not the rotation - and the result looks like jitter. Here is a video to illustrate. To exaggerate the effect, it uses a very long physics step, and was also slowed down using a video editor.

    PhysicsRotationJitter3.gif

    The take-home from all of this is that if you want to control your non-kinematic Rigidbodies in an interpolation-compatible way, you can use velocity and angularVelocity, but not MoveRotation. TIL.

    When properly setting rb.velocity and rb.angularVelocity, the result is perfect, even at the default 0.02 physics step:

    PhysicsRotationJitter2.gif
     
    Last edited: Apr 27, 2023
  44. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
  45. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    flashframe likes this.
  46. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,086
    Rigidbody.MoveRotation
    Rotates the rigidbody to rotation.

    Use Rigidbody.MoveRotation to rotate a Rigidbody, complying with the Rigidbody's interpolation setting.

    If Rigidbody interpolation is enabled on the Rigidbody, calling Rigidbody.MoveRotation will resulting in a smooth transition between the two rotations in any intermediate frames rendered. This should be used if you want to continuously rotate a rigidbody in each FixedUpdate.

    Set Rigidbody.rotation instead, if you want to teleport a rigidbody from one rotation to another, with no intermediate positions being rendered.

    -------------

    How has this not previously been discovered by the claimed millions of Unity users?
     
    Last edited by a moderator: Apr 27, 2023
  47. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    antoinecharton and flashframe like this.
  48. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Ah that makes sense, thanks for following up
     
  49. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    By coincidence I hit the very same issue today, but with Rigidbody.MovePosition instead of Rigidbody.MoveRotation.

    Like Gregory has posted, moving to setting velocity directly appears to clean up the stuttering with interpolation working as expected.
     
    antoinecharton likes this.