godotengine / godot

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

KinematicBody not pushing RigidBody at certain angles #16329

Closed ghost closed 6 years ago

ghost commented 6 years ago

Using the latest release. If I have a kinematicbody run into a rigidbody head on, it doesn't push it. But approaching from an angle does. I have sleep turned off on the rigidbody.

Here is a video showing the issue: https://youtu.be/4XsyRHYRI94

vkbsb commented 6 years ago

it would help if you shared the sample scene.
I've tested with a sample scene and it seems to be working fine for me. Attaching my sample project. BugTest.zip

ghost commented 6 years ago

Here is my project - CollisionTest.zip

eon-s commented 6 years ago

Well, Kinematic bodies using move are not supposed to be able to push a rigid since the method prevents overlaps (you need to create another body that collides with the rigids), I think the push is a bug here...

ghost commented 6 years ago

@eon-s That's what I thought, and I was checking for collisions and then applying an impulse. But someone pointed out that if you turn off can_sleep on the rigidbody you can push them with a KinematicBody. So there is a bug somewhere, but I don't quite know what the expected behavior.

eon-s commented 6 years ago

No, the sleeping bodies can be pushed by kinematics moved by set position/translation. A kinematic body child of the main body with 1% bigger size in shape can do that effect, but the move one should never touch the rigid.

Godot physics, on the other hand, has the correct behavior, so is a Bullet problem.

eon-s commented 6 years ago

Here is the same example in Godot Physics with a KB added as child, 2nd KB shape can be disabled to see how bullet should do it too (GP rigids seem to have more inertia so but the push effect is there).

CollisionTestGodotPhysicsKBChild.zip

ghost commented 6 years ago

Thanks a ton @eon-s - That makes sense. I played with your example and it seemed the second kinematic body only pushed the ball if the scale was set to 1.07 or higher from the front. The other angles seemed to be fine. Any ideas on that? That was in the Godot Physics engine.

eon-s commented 6 years ago

There could be some precision issues in the separation process (which may be affecting bullet too, making it push the rigid).

akien-mga commented 6 years ago

CC @AndreaCatania

AndreaCatania commented 6 years ago

The problem is that the kinematic bodies doesn't push the rigid bodies so it's not possible by the kinematic body to wake up the rigid. I've already a solution, I'll make a PR soon.

@akien-mga also thanks you to let me know this issue.

AndreaCatania commented 6 years ago

Fixed #16757

eon-s commented 6 years ago

The fix means it now won't stop on collide with rigids? (that is not the way Godot Physics 3D and 2D works)

AndreaCatania commented 6 years ago

True, but think about that. A kinematic body has always infinite inertia; it means that it can't never be stopped by a rigid body also is the opposite for the rigidbody that should always be pushed away by kinematic body.

In this moment the kinematic body has inertia 0 against rigidbody and can't never move a rigidbody.

Also in this moment both bullet and Godot physics has the same behaviour since neither godot is able to push a rigid body (due to the explanation above)

eon-s commented 6 years ago

I understand that, Godot physics also created the need for complex body setups for interacting with rigid bodies, if this will be the new behavior I think it should be made for 2D too (there will be a revision for 3.1 if I'm not wrong, a good chance to break this).

AndreaCatania commented 6 years ago

The solution to add a kinematic as child of kinematic body basically move the child kinematic body in the position where the the parent is. Then the child will overlap a bit the RigidBody, so the rigidbody react to this overlaps with a movement.

As you see this is not a solution but a weird work around that for some reason works.

lane-s commented 6 years ago

@AndreaCatania I'm not sure I understand the workaround. So if I have a KinematicBody and I want it to be able to push rigidbodies, then I need to to add a RigidBody set to MODE_KINEMATIC as the child of the KinematicBody?

eon-s commented 6 years ago

@lane-s the workaround used a KinematicBody as child of the main body, so the transform of the child can overlap rigids to move them, but this is fixed now, not sure if is on 3.0, though.

AndreaCatania commented 6 years ago

I said that this work around is really bad, and I don't back it. however if you use the last version of engine you don't need any work around since I maked a change that allow all kinematics body to push the rigids