0 votes

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?

in Engine by (391 points)

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.

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.