Pushing a RigidBody2D with a KinematicBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mrmtonio

enter image description here
I want this kinematicbody (left) to push this rigidbody (right) and make it roll.

To make it roll i presume I’d have to use add_force() or apply_impulse(). But I can’t figure out how to detect collision. The best I could come up with is this:

enter code hereextends RigidBody2D
func _ready():
pass
func _process(delta):
if $KinematicBody2D.get_position() == position:
	add_force(Vector2(0,0),$KinematicBody2D.direction*300*delta)

But that’s really shitty code, hope it gets the point across.

(I’ve also been trying it other ways with get_slide_count() or get_slide collision(), but the $KinematicBody2D on the code returns null, although it is on the same scene, I’m trying to figure that out too.)

:bust_in_silhouette: Reply From: markopolo

If you have code that moves the kinematic body, that should be enough: kinematic and rigid bodies always apply forces to rigid bodies they collide with.

As for why get_slide_count returns null, you might need to enable contact monitoring on the kinematic body and set the contacts reported to a number greater than zero. I’m not sure about that though, I’m not very familiar with messing around with slide info from kinematic bodies.