Hello all, I am making a game that is using 2d assets in a 3d environment. I have very basic setup going, with a camera3D with interpolation and some smoothing to follow a cameraTarget I have as a child of my player character. I notice that when I run the game, when both the camera and the player are moving at the same time there is a bit of a blur/jitter around the edges of the character that is hard on the eyes. I have a 165 hz monitor, and when I turned my monitor down to 60hz I noticed that this problem was fixed. The other way I discovered to fix the problem was by putting the camera movement code inside of the _PhysicsProcess function instead of _Process. However neither of these feel like good solutions, from my understanding its not good practice to put camera movement in _PhysicsProcess and on the other hand I want my game to look and run properly on all common refresh rates. I am not sure how to approach this, as I am kind of new to Godot and working with graphics in generall so any advice/help on how I should approach this situation would be greatly appreciate!
#Help figuring out how to approach blurry/jitter effect of camera movement.
11 messages · Page 1 of 1 (latest)
Ah, render framerate vs physics framerates.
You have a few options to consider here, depending on what your game is.
One solution is using a fixed framerate for physics - commonly 60hz, or for some games, 125hz)
Godot's default is 60hz. So, when your render's framerate is in sync with the physics frames, and it's smooth (for 60fps)
But if you wanted to play on your default refresh rate of 165hz, you'd want to have a render rate a bit higher than 60.
this means that for every fixed interval of physics tick, the render frame will end up in a different spot in time. it's small enough to cause this jitter you notice.
there's a few solutions to that problem, but the easiest i've found has been like so:
-
get the current position of the object each render frame and keep it on the next frame to get the distance between the two frames
-
interpolate between these two points by the fraction of physics frames you're in between
i'm working currrently on a 3D movement FPS. ideally i'd like the camera to be as smooth as possible! so first we should set a few boundaries
- my physics framerate is 125hz.
- my render framerate is some number over 30. On my own computer, I use a 144hz monitor.
in code this would look something like:
func _process(_delta: float) -> void:
_RefreshTransform()
_interpolate()
return
func _interpolate() -> void:
if Engine.get_frames_per_second() > Engine.physics_ticks_per_second:
set_as_top_level(true)
for i in range(3):
global_transform.origin[i] = lerpf(
_tr_prev.origin[i],
_tr_curr.origin[i],
Engine.get_physics_interpolation_fraction()
)
if _target is Node3D:
rotation.x = (_target).rotation.x
rotation.y = (_target).rotation.y
#rotation.z = (_target).rotation.z
else:
set_as_top_level(false)
global_transform = _tr_curr
return
where RefreshTransform simply updates the stored transform of _target and then interpolates between the two
there's a distinction to make though for camera control and for moving objects
the above works for a camera, because rotation of the camera happens on input and we want that to happen when it happens
if you want to do this for a moving object you may want to also lerp_angle or consider other ways to do rotation math (slerp with normalized quaternions, etc - this is reallllly preferred)
https://github.com/lawnjelly/smoothing-addon this is probably much more complete
This is a very detailed and thoughtful response tysm! When I get time to work on my game again this weekend I'll look into this and give some stuff a try, much appreciated.
good luck 👍 i try to write the responses i wish i had found when i was dealing with this stuff.
also, my bad - you're using GD4, there is a branch for that smoothing addon in 4.x but i linked to the repo in general, which is for 3.x by default
No problem I'll checkout that other branch :) appreciate it I really want to like Godot and keep learning 
it's been a blast i have really enjoyed - keep it up and you're bound to make something cool