Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GodotPhysics] KinematicBody3D with move_and_slide() move bumpy/jittering on flat surface #45060

Closed
Tracked by #45333
archerallstars opened this issue Jan 9, 2021 · 3 comments

Comments

@archerallstars
Copy link

Godot version:

  • Godot 3.2.4 beta 5

OS/device including version:

  • Windows 10 Home 64-bit, Version 20H2, OS build 19042.685
  • Intel® UHD Graphics 620, Version 27.20.100.9126

Issue description:

I move a KinematicBody3D with velocity input to the move_and_slide() using the GodotPhysics engine. It has a bumpy ride on a completely flat floor(StaticBody), as shown in my screen recording below:

2021-01-09.19-31-11.mp4

Steps to reproduce:

  1. Open the reproduction project.
  2. Choose the appropriate Vector 3 Print in the Player's script available at the inspector tab.
  3. Run the project, the Player will move bumpy/jittering on a flat surface.

Minimal reproduction project:

test.zip

@nonunknown
Copy link
Contributor

While the bug isnt solved in general, I could solve this problem in my project, so I recommend this to you:

Option 1:

  • Scale the child-most nodes until when you change cordinates and its almost integer only i.e: before if you move the cube in the editor from 0.01 to 0.05 now if you move it (due to huge scale) from 1 to 5, this is "easier" for physics engine to calculate

Option 2:

  • Use a plugin called smoothing-addon and since it will make things smoother you can also change physics Fps to something like 15-30 fps this will save a lot of resources 👍

@archerallstars
Copy link
Author

While the bug isnt solved in general, I could solve this problem in my project, so I recommend this to you:

Option 1:

  • Scale the child-most nodes until when you change cordinates and its almost integer only i.e: before if you move the cube in the editor from 0.01 to 0.05 now if you move it (due to huge scale) from 1 to 5, this is "easier" for physics engine to calculate

Option 2:

  • Use a plugin called smoothing-addon and since it will make things smoother you can also change physics Fps to something like 15-30 fps this will save a lot of resources 👍

Thanks for your suggestions ❤

Option 1: I think it's too complicated as a solution. Therefore I put a condition before applying the gravity instead. Since GodotPhysics does a reliable job to detect the floor with is_on_floor(), unlike the current Bullet engine which is known to have this kind of issue, i.e. #33833 or #45058. Moreover, testing whether the body is on the floor before applying gravity makes the falling of the body be more simple to implement and more natural, as the gravity value will be interpolated by the physics instead of being at the maximum value all the time.

Option 2: I tried the smoothing-addon but it didn't help at all. I believe this issue is not relating to the jittering from the un-alignment of the PhysicsRep and VisualRep, which the addon is trying to solve. If you watch the issue closely, you will see that the y translation of the cube changes its position while being moved on a flat surface. It can only mean that there's a problem with how the physics work somehow.

@fabriceci
Copy link
Contributor

You forgot to assign the result of "Move and slide" to the velocity.

Screenshot 2021-09-20 at 23 27 14

For the record I added the GDScript version (with the fix).

extends KinematicBody

var gravity = 50.00000
var gravity_max = 100.0000000
var speed_acceleration = 50.00000
var speed_max = 100.00000
var velocity = Vector3(0,0,0)

func _physics_process(delta):
	gravity_pull(delta)
	player_velocity(delta)
	velocity = move_and_slide(velocity, Vector3.UP)

func gravity_pull(delta):
	velocity.y = clamp(velocity.y - delta*gravity, -gravity_max, gravity_max)

func player_velocity(delta):
	velocity.x = clamp(velocity.x + delta*speed_acceleration, -speed_max, speed_max)

func _input(event):
	if(Input.is_action_pressed("ui_select")):
		velocity.y = 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants