0
\$\begingroup\$

So I have no problem getting it to work with a characterController. It looks smooth when I walk/run/jump around. But I wanted to make it work with a rigidbody. There was no problem when I tried implementing it with 2D. I could get it to work for both a sidescrolling and a top-down game. But of course, thats quite "easy". All you have to do is either make the camera a child or set its position to that of the player(or use cinemachine, but I am to lazy to learn it properly)

But when I tried implementing it for a first-person game, you could see how the edges of things got "shaky" or "Blurry" when you move or jump, why is that? I dont get that problem with characterController. I have the same setup:

(1)An empty object as the player with scripts(and characterController/RigidBody)
(2)(child)A capsule object as the visual and collider
(3)(child)The Main Camera
See: enter image description here enter image description here

(So I cleaned up and took away some code to make it easier to read, so yes you can jump in all eternity)

Here is the code: https://imgur.com/a/iWQTgUA enter image description here So I have a script for all the input called "PlayerInput", I then have 3 methods where I gather that input so I can use it, Move, look and Jump(I am a little confused on where the Jump force should be, its physics based, so I probably should have saved both Jump and Move with moveDirection and then applied that in FixedUpdate)

I have tried changing to LateUpdate for the camera, but the camera is a child of the player. So it should move at the same time, right? So that didnt work. I tried changing the RigidBody to Interpolate but that also didnt work. What am I supposed to do?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Please include code as text, not as an image. This improves search hits, and makes it easier for folks to copy-paste parts of your code when preparing answers to solve your problem. Visit the help center if you need support formatting it correctly. \$\endgroup\$ Commented May 21, 2024 at 19:42

1 Answer 1

1
\$\begingroup\$

The rule when moving an object with a physics rigidbody is "never write to the transform". You want the movement controlled 100% by the physics engine. If you mix moving it with the body and the transform component, the two systems end up fighting each other.

This line is the culprit:

transform.rotation = Quaternion.Euler(0, _xMouse, 0); 

This writes a value to the transform, which forces the two systems to reconcile. In the process, it disables interpolation for this frame, leading to juddery movement.

Instead, use _rb.MoveRotation, which keeps the rotation under the control of the physics system, where interpolation can keep working as desired to smooth out the update rate mismatch.

\$\endgroup\$
1
  • \$\begingroup\$ aaa that makes sense, "Keep the physics engine and transform seperate", MoveRotation solved the problem! I also tried "_rb.rotation" which sounded similar, but it prodoúced shaky movements, so I guess not. \$\endgroup\$ Commented May 24, 2024 at 12:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.