Does the Move Local function take collision into account?

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

I was making simple platform mechanics. I used a kinematic player with a rectangle collision shape. i used this code for the horizontal movement:

move_local_x(horizontal_movement, false)

the horizontal movement variable is an integer that either 1, 0, or -1 depending on the players input, and then mutiplied times the speed variable and delta.

this all worked fine, but then I tried implementing gravity the same way:

move_local_y(gravity * delta, false)

this also worked, but when I added a ground with a collision shape 2d, the character passes through it!

Is this the fault with the code, or is it something else?

IIRC most physics nodes utilize collision detection, and their associated functions (move_and_slide, move_and_collide, etc.) handle all of the proper movement. Functions such as move_local_x() and move_local_y()only translate things based upon the node’s axises, and doesn’t seem to take the physics engine (and its associated collision system) into account.

Ertain | 2019-11-03 19:16

Thanks, I used the move_and_slide() function and it worked perfectly!

Millard | 2019-11-03 20:14