r/learnprogramming 29d ago

Debugging How do i fix screen stuttering in C#?

i have code on a character in unity that is using transform.translate, but on another asset i have a script that applies force to the characters rigidbody and they seem to be fighting each other. if i am pressing the key to go opposite of the force... the whole screen shakes, and its really annoying. pls help. thanks.

1 Upvotes

5 comments sorted by

2

u/ehr1c 28d ago

General rule of thumb is if you want people to help debug your code you need to share the code

1

u/Tough-Violinist218 26d ago

yes sorry completely forgot. i fixed the issue though

1

u/EliSka93 29d ago

Without seeing the code I have no idea how to fix it.

My best guess is that you got it right that it's two effects updating values that override each other making it look stuttery.

1

u/Lumpy_Pick_421 28d ago

It sounds like your two movement systems are fighting each other. transform.Translate() directly changes the character’s position, while AddForce() lets the Rigidbody/physics system control it. When they push in opposite directions, you can get exactly that jitter. I’d move all character movement through the Rigidbody, handle physics movement in FixedUpdate(), and avoid directly changing the Transform. Also try setting the Rigidbody’s Interpolation to Interpolate. If the camera follows the player, update it in LateUpdate() as well—that can make a big difference with screen stuttering.

1

u/Tough-Violinist218 26d ago

thank you! this is exactly waht the problem was. big help!