How to disable forces effecting a kinematic, & still allow collisions/forces on colliding rigid body?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zyrixian
:warning: Old Version Published before Godot 3 was released.

Hi,

I’m having difficulty figuring out how to keep a kinematic body from being moved by an impact with a rigid body. Even if the kinematic is stationary the rigid body will sometimes cause the kinematic to move when hit on one of the angled edges of the collision polygon.

I’ve tried forcing it to go back to it’s correct location by using set_pos, but this sometimes causes strange behavior with the collisions. I’d like to just have the forces not effect the kinematic body at all. But still have the rigid body bounce off. Is that possible?

Forces never affect kinematic bodies but rigid bodies can prevent them from moving (with move or move_to ).

Avoid the use set_pos with physics objects unless you know what you are doing, and always work at _fixed_process.

How are you moving the rigidbodies?

eons | 2016-10-12 17:03

I have the same problem. Rigids are actually moving the kinematics, but only after I implemented the code for x/y movements. So I believe it has something to do with the gravity (y direction movements) applied to the kinematicbody. I’m not that troubled by the effect so I did not try to fix it or understand it.

MrMonk | 2016-10-14 11:30

So after some more examination. It turns out the kinematic body is definitely being effected by the rigid body. However this only seems to be happening when the kinematic body is being moved.

The rigid body is only being move by setting its linear velocity. No other movement is being used except set_pos when the object is created.

The kinematic body should only be moving left and right, however while it is moving it will shift up or down when impacted. My assumption is that this is happening to try and get the object out of collision, however to my knowledge this shouldn’t be happening…

I always use move to move the kinematic, i only started using the set_pos to make sure the kinematic stays on it’s horizontal path, since it’s being pushed off.

I also am only using _fixed_process.

and gravity is disabled but I agree w/ MrMonk, I actually see it when movement is applied to the kinematic.

Here is a gif of what’s happening. The paddle is the kinematic:

zyrixian | 2016-10-17 20:17

Your assumptions are right ^^

When you use set_pos, the kinematic works as a static (like for use with a moving platform); when you use move, it tries to not overlap while announcing collisions and adjusts its position to a correct one.

The fast rigid may have a little overlap and move() affects the kinematic before the rigid bounces off.

So, moving with set_pos may solve the problem.

eons | 2016-10-18 03:29

I did try that before and I seemed to run into this issue, especially at high speeds.
Notice how the rigid passes through the kinematic, and at the end the rigid somehow gets stuck within the kinematic. This issue seemed to be reduced when using move only. However neither outcome is ideal. I assume this is not the final behavior of the physics system, and is perhaps buggy behavior…

I’m currently using move and when a collision is detected I’m using set_pos to reset the kinematic to the correct y position. This seems to be a decent fix, but I still run into the below at high speeds.

in the meantime any suggestions on a work around, or another way to accomplish the same thing without rewriting the physics system? (I’m quite new at this so thanks for your patience!)

zyrixian | 2016-10-18 04:43

High speed rigids always require continuous collision detection to avoid tunelling (there is a checkbox in the inspector and the corresponding funcion), they are never by default on (on any engine) for performance reasons.

If you want/need to use kinematic body as the main body you can do

KinematicBody2D (+script)
|-Sprite
|-KinematicBody2D
         |-CollisionShape2D

You can attach many bodies to the main node and all will follow it’s parent motion (being kinematics, with a static behaviour), careful to not overlap colliders if are on the same pair layer/mask.

eons | 2016-10-18 14:07