godotengine / godot

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

KinematicBody2D movement jitters when sync to physics is turned on #28181

Closed Cevantime closed 4 years ago

Cevantime commented 5 years ago

Godot version: Godot 3.1 official

OS/device including version: Linux Mint Nvidia GTX 1060 (v. 396)

Issue description: When "Sync to physics" in turned on for KinematicBody2D (didn't check for 3D), the movement of the KinematicBody2D -if animated with AnimationPlayer for instance- gets jittery. When turned off, it becomes smooth again. Not sure if it's solvable or it's even an issue since it may be caused by the fact the Kinematic is synced with physics but I'll be glad if someone could explain why this happens.

Steps to reproduce: Simply create a KinematicBody2D in your scene and attach a Sprite to it. Animate the body (with an AnimationPlayer) with a linear movement and activate the Sync to Physics property. The effect is more obvious with some zoom on the camera

Minimal reproduction project: Test.zip

Raphael2048 commented 5 years ago

I have tried to solve this problem and I figured out the reason, but I don't know how to fix it now.When you change a KinematicBody2D's position with AnimationPlayer, if you set "sync to physics" to true, https://github.com/godotengine/godot/blob/cfbf23e339c110ba55183e9a75b11fa0b9ea6c7c/scene/2d/physics_body_2d.cpp#L1468-L1476 those code will set a physics transform state and set origin position back, but it also trigger notification here: https://github.com/godotengine/godot/blob/cfbf23e339c110ba55183e9a75b11fa0b9ea6c7c/scene/2d/collision_object_2d.cpp#L74-L89 then the physic transform state will be set again with a previous wrong value. so the Kinematic can only update its position per two frames and jitters. It seems that "Sync to physics" is meaningless at all for now , @akien-mga

Cevantime commented 5 years ago

@raphael10241024 thanks for your response. I might try to make a pull request if I got some time to work on it.