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

KinematicBody2D pushes RigidBody2D through the ground when standing on them #37427

Open
Tracked by #45334
Stay1444 opened this issue Mar 30, 2020 · 8 comments
Open
Tracked by #45334

Comments

@Stay1444
Copy link

Godot version:
Im using Godot 3.2

OS/device including version:
Windows 10 Home, using Ryzen 5 3600x 16 gb Ram GTX 1050.

Issue description:
The Rigid Body 2D works fine like in this example -> https://imgur.com/a/vLhaJiy
when there are a few of them interacting. If i throw a bunch more of boxes like here
->https://imgur.com/a/ReZ5Oxb
that happens. Is not solid enough even to the player to stand on. Is there a fix? Because that feels like a piece of paper intead of a solid box.

Steps to reproduce:
Add 20+ RigidBody2D coliding each others or make a kinematic body 2d try to stand on.
Mass isnt important, doenst change anything.

Minimal reproduction project:
https://up2sha.re/file?f=IJ489K
https://mega.nz/#!RqxQWKLL!vNu4gZPu725KbHL5eBPPc09mLzMGLzOk1ZpoAN9ylXU

If you have time, i recommend you to see the project, otherwise it will be difficult to understand.

@bemyak
Copy link
Contributor

bemyak commented Mar 30, 2020

Few things to note here:

  1. From move_and_slide docs:

    linear_velocity is the velocity vector in pixels per second. Unlike in move_and_collide(), you should not multiply it by delta — the physics engine handles applying the velocity.

    So, you don't need to multiply your gravity by delta.

  2. At the end of _physics_process function you are updating velocity variable, which is correct. But then in get_input() function you're resetting both x and y components of it. Instead you should decrease x like this: velocity.x = lerp(velocity.x, 0.0, 0.5) and for y: velocity.y += jump_speed.

  3. Pushing RigidBodies is expected behavior. From move_and_slide docs:

    If infinite_inertia is true, body will be able to push RigidBody2D nodes, but it won't also detect any collisions with them. If false, it will interact with RigidBody2D nodes like with StaticBody2D.

    If you want to have physic-based interactions between your character and RigidBodies, consider changing it's type form KinematicBody2D to RigidBody2D or RayCast2D

@bemyak
Copy link
Contributor

bemyak commented Mar 30, 2020

As for

If i throw a bunch more of boxes like here that happens.

I have an open PR that fixes it. I really hope it'll be reviewed at some point....

Hope this will help.

@Calinou
Copy link
Member

Calinou commented Mar 30, 2020

@bemyak Due to the heavy refactoring currently ongoing in the master branch, it'll take a while for PRs to be reviewed. This is why the number of open pull requests has been increasing lately. Sorry for the inconvenience.

@bemyak
Copy link
Contributor

bemyak commented Mar 30, 2020

@Calinou , sure, I understand, no worries :)

@Stay1444
Copy link
Author

Stay1444 commented Mar 30, 2020

3. changing it's type form KinematicBody2D to RigidBody2D or RayCast2D

The problem is that isnt recommended to use a RigidBody as a player/character. I dont really know why.

And for the delta, i cant remove it because the character will stop jumping.

@Anutrix
Copy link
Contributor

Anutrix commented Mar 30, 2020

Could be a duplicate of #2092.

@nezvers
Copy link

nezvers commented Sep 13, 2020

  1. changing it's type form KinematicBody2D to RigidBody2D or RayCast2D

The problem is that isnt recommended to use a RigidBody as a player/character. I dont really know why.

And for the delta, i cant remove it because the character will stop jumping.

It is recommended because typical player movements are harder to implement. RigidBodies would need calculations for counter forces to make them snappy movements. Although, if that is taken care of properly, it is easy to add joints to influence RigidBodies like grappling hook with spring.
Problem with RigidBody2D is small scale movement collision imprecisions - buggy if you ask me.

@pouleyKetchoupp pouleyKetchoupp changed the title RigidBody 2D physics dont work fine. KinematicBody2D pushes RigidBody2D through the ground when standing on them Jan 15, 2021
@pouleyKetchoupp
Copy link
Contributor

Can still reproduce in 3.2.4 beta 5.

Zipped MRP, adapted to be easier to use on small resolution:
StandOnRigidbodies.zip

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