Jittery Movement In 3D. Fixed when move_and_slide is under process

Godot 4.4.1

I tried uploading a video here but unfortunately new users can’t upload files. I’m not good at coding since I’m a beginner but I’m following a tutorial to make an FPS game. Problem is I can’t get the movement to work properly. The movement is very jittery and it happens because my character skips steps when he walks. I found that out by detaching the camera and seeing the character move from a fixed camera - he just sort of teleports. This doesn’t happen when jumping though. Jumping works fine and if I walk forward then jump, the movement forwards is smooth. Like I said I’m not good at coding but I tried following so many tutorials on YouTube and they all work for them (the creator) but not for me. From my understanding, it’s because the _process function and _physics_process update at separate times. This is confirmed because when I copy the move_and_slide function under _process, the movement works correctly. However, I can’t use that fix because it breaks the physics. No matter what code I use, I have the same problem .I only have one script in my game and that is the player script. Previously I tried detaching the camera and making it move separately and I had the same issue. It seems that my character just skips steps. I deleted my code and started fresh so the code I’m currently using is the default template for CharacterBody3D. I’ll copy the code below anyways but it’s just the default.

*My Code:

extends CharacterBody3D


const SPEED = 5.0
const JUMP_VELOCITY = 4.5
var direction

func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta
	else:
		velocity.y = 0

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		

	var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()

My hierarchy goes:

World
          DirectionalLight3d
          WorldEnvironment
          CSGBox3D
          CharacterBody3D
                      MeshInstance3D
                      CollisionShape3d
                      Animation
                      Node3D (Camera Pivot/Head)
                           Camera3D

Do you have a high refresh rate monitor? say 144hz? The default physics tick step is 60 per second so it will appear at lower framerate if you are use to higher. You can increase the ticks per second or enable physics smoothing in the project settings.

Yes I do. But I tried using Physics Interpolation, changing the physics ticks to match my monitor (165), tried playing with the jitter fix (don’t remember the name completely) and enabled/disabled V-sync. Tried turning off Freesync etc. It works very well in 2D.

Update: It somehow fixed itself when I created the player’s own scene.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.