godotengine / godot

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

RigidBody2D passes through walls/objects when pushed by a KinematicBody2D #27652

Closed TheRadMatt closed 2 years ago

TheRadMatt commented 5 years ago

Godot version: 3.1

Issue description: Rigid Bodies pass through walls when pushed by Kinematic Bodies. This doesn't happen in 3.0.6.

In 3.0.6: https://i.imgur.com/k7vJdoM.mp4

In 3.1: https://i.imgur.com/BhkKt0G.mp4

It doesn't just happen in the platformer demo, I noticed this problem in other projects as well.

xiico commented 5 years ago

The same thing is happening to me, but in my 2D project.

3.0.6 3 0 6

3.1 3 1

ghost commented 5 years ago

Similar experiences, and with CCD enabled they can still tunnel.

takhimi commented 5 years ago

Happens to me on my 3D game project also.

TheRadMatt commented 5 years ago

Is there a possibility this will be fixed soon (in 3.1.1, perhaps)? The Rigid Bodies are basically unusable because of this and 3.2 won't come out for quite some time probably.

rogeriodec commented 5 years ago

My objective: to prevent a RigidBody (or KinematicBody) from "crossing" the StaticBody (like a wall or floor).

I have a script that "pushes" a RigidBody (Cube) with the mouse. I inserted a print (RigidBody.get_translation ()) into func _input ( to detect any movement of the mouse by pushing the RigidBody.

And I connected a body_entered signal in the RigidBody to show any RigidBody collision with the floor (StaticBody). As you can see in the animation, in the beginning, the RigidBody is resting (in a collision) with the StaticBody. Then I start to push the RigidBody down and as you can see, the body_entered signal fires only multiple_input events after.

In my understanding, the body_entered signal should be triggered at the very moment the collision occurs. But this does not seem to be happening. How to solve this?

Zireael07 commented 5 years ago

Body_entered fires every time the other body is entered. I don't know what the resolution of the check is, why it detects so late.

Check not only for body_entered, but also for a boolean of your own creation. Switch the boolean the moment body_entered first fires.

rafaelgdp commented 5 years ago

I'm here to confirm that this also happened to me in a simple 2D project I was implementing. A KinematicBody2D pushes the RigidBody2D through walls and floors as if it were nothing.

ghost commented 5 years ago

Is there a possibility this will be fixed soon (in 3.1.1, perhaps)? The Rigid Bodies are basically unusable because of this and 3.2 won't come out for quite some time probably.

Not too likely. I wish I could say otherwise, but personally I have benched these for most uses since 2.1, and over the previous year I have the impression it is an area that lacks contribution.

Juan may dabble a bit in the 2D physics here and there to patch things up, and it is something he talks of fully rewriting, but it has been bumped to the next version with each stable release. He may be the only one currently that can take the job on, but I imagine his priorities are necessarily between things like rendering work and general maintenance.

takhimi commented 5 years ago

Maybe Godot will have new physic engine ? Nvidia flex ? https://www.youtube.com/watch?v=agEjyOTigF8

takhimi commented 5 years ago

Maybe this hopefully could resolved the problem ? https://github.com/godotengine/godot/pull/27415

slapin commented 5 years ago

This seems not physics related as does not happen with normal Bullet physics objects with separate project. I think a problem is due to infinite inertia and other stuff related to KinematicBody. It is very hard to implement collision so that it prevents Kinematic-Rigid collisions as it hits RigidBody with inadequate momentum. Would be nice if it was possible to avoid collisions completely (consider RigidBody a wall) or be able to override momentum or mass and force for Kinematic-Rigid collision.

slapin commented 5 years ago

I think there is a need for tutorial for dynamic character controller based on RigidBody as for other engines, this will make collisions much more natural. Dunno how to merge that with root motion but as NaughtyDog did that I think everybody else can do it too.

ghost commented 5 years ago

@slapin At least for 2D, one isn't going to have much success at creating a stable and reliable dynamic body character of any complexity with the presently outstanding issues. I'm not sure what the state of affairs is for 3D.

hiulit commented 5 years ago

Same here #27593

rdmtt commented 5 years ago

Turns out the problem is with _infiniteinertia value which was introduced as an addditional parameter in _move_andslide function in 3.1. In order to fix the issue, you need to set it to false and then write code that will move rigid bodies on collision with the kinematic. Thanks to KidsCanCode for figuring this out (his video).

I wish someone announced that there was a new parameter added :/ It would save some of us a lot of confusion.

Edit: Also, I believe this parameter should be set to false by default in the next releases.

rafaelgdp commented 5 years ago

I also saw this video @rdmtt ! I always thought this infinite inertia aspect of Godot's Kinematic Bodies had something to do with this weird behavior, but I never got to investigating it further! KidsCanCode rocks!

akien-mga commented 2 years ago

This is indeed not a bug but a configuration option as pointed out by https://github.com/godotengine/godot/issues/27652#issuecomment-519927731.

This API has been improved significantly in 4.0 IIRC, so this might be less confusing now.