How do I make KinematicBody 3D to be pushed out by other objects after translation?

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

So, I have a kinematic body 3D (Which is a cube). I need to translate it every frame to where the ray hits. What it does right now is that it stays half-way in the ground or any object that it hits because it is translated to the exact point where the ray hits. So, how do I make it so it would be pushed out from ground or other object after translation? I tried everything (I also NEED to use translate on it, can’t otherwise)

:bust_in_silhouette: Reply From: kidscancode

A kinematic body only collides when using its movement methods. You must use move_and_collide() or move_and_slide() to move it. translate() moves a Spatial object but will not give you any collision or separation.

:bust_in_silhouette: Reply From: johnygames

You said you use a ray to detect objects (let’s call them obstacles) and “teleport” your KinematicBody to their location. Why don’t you simply get the location of the obstacles and translate the KinematicBody to their location + some offset. In other words, don’t teleport the KinematicBody to Obstacle.translation.z, but teleport it to Obstacle.translation.z+offset