godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.29k stars 21.05k forks source link

Jitter and Shaking issue in Character2D node using physics process #94293

Open lyderX05 opened 3 months ago

lyderX05 commented 3 months ago

Tested versions

Tested on version Godot 4.2.1 and Godot 4.0

System information

Windows 11 - Godot v4.2.1

Issue description

Godot Engine v4.2.1

Jitter in Character2d Node move right and left or top and down

https://docs.godotengine.org/en/stable/tutorials/rendering/jitter_stutter.html

Below are some steps done to resolve the Jitter issue

Update the Max FPS to 60 and also make sure that the ticks_per_second is 60 still jitter issues

Tried change the ticks_per_second to 60 and Increase the Max Physics step per second, but issue is still there.

extends CharacterBody2D

const SPEED = 300
var viewport_size
const MARGIN = 20

func _ready() -> void:
    viewport_size = get_viewport_rect().size

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    pass

func _physics_process(delta: float) -> void:
    var direction = Input.get_axis("move_left", "move_right")
    velocity = velocity.normalized()
    if direction:
        velocity.x = direction * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)

    move_and_slide()

Steps to reproduce

Create a Character2D player and add the sprite 2D and Rectangle collision 2D node. Once done configure the script for Character2D Node and add the following below code

extends CharacterBody2D

const SPEED = 300
var viewport_size
const MARGIN = 20

func _ready() -> void:
    viewport_size = get_viewport_rect().size

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    pass

func _physics_process(delta: float) -> void:
    var direction = Input.get_axis("move_left", "move_right")
    velocity = velocity.normalized()
    if direction:
        velocity.x = direction * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)

    move_and_slide()

    if global_position.x > viewport_size.x - MARGIN:
        global_position.x = -MARGIN

Sprite2D will contain the simple PNG image of character and run application to check if character move left to right.

Note: move_left and move_right is the Input mapping to A(physical) Left(physical) and D(physical) Right(physical) respectively.

Character shows the jitter and shaking response.

Sometime it works for few minutes after it again shows Jitter effect and below are steps also followed provided in document: https://docs.godotengine.org/en/stable/tutorials/rendering/jitter_stutter.html

Still no effect.

Minimal reproduction project (MRP)

Added player.tscn and png file in below zip file, with script

Game.zip

jmattspartacus commented 3 months ago

I'm not seeing an effect I'd call stuttering/jitter on Linux 5.15 x86_64, maybe windows specific? Is there anything specific that you do immediately before the stuttering happens other than move left/right? Is "Max Physics Steps Per Frame" still set to 8?

lyderX05 commented 3 months ago

No, I added only base physics process code, I already checked frame rate on which machine and screen is working by enabling the debug frame rate and it was working on 60 fps but still there was issue.

markdibarry commented 4 weeks ago

The MRP provided does not contain a project, so I was unable to test this, but from the description it sounds like the same behavior as #93048