0 votes

Any ideas why my KinematicBody2D character is instantly changing y position when I am expecting it to fall with gravity? This is only happening in one very specific part of the tilemap. Basically, falling off a ledge where the ground tile is 16 px below the ledge. Any further distance drop and the character falls as expected, smoothly with gravity applied.

Here is a video with collision shapes on. I try to demonstrate the "teleport" (four areas in the middle, one on the left) and normal falling. You can see some raycasts (used for ledge grab, head stomp, etc.), but I've done it with them all disabled, and it does not make any difference.

I have also tried changing the default project gravity (used in code) and the rapid jump still occurs for this area of the tilemap, while other movements are affected as expected.

My player movement code is too messy to share (it's about 800 lines :-|), and I have no idea which part of it is the problem. So I'm looking more for a recommended troubleshooting direction or ideas. The approach is based on https://godotengine.org/asset-library/asset/120.

Thanks!

Tileset and character by penusbmic (https://penusbmic.itch.io/free-dungeon-ruins-tileset).

Godot version 3.2.3
in Engine by (29 points)

For me it looks like your code does not reset y-"impulse" at all cases. Your implementation of falling probably looks like

if is_falling():
  impulse.y += gravity
if is_on_floor(): # I think this check is failing in some cases
  impulse.y = 0.0
....
move_and_slide(impulse)

because in some cases your y-component of impulse does not reset, it builds up to big values, resulting into "teleportation" effect on edges.

If this is not the issues, then without example project it will be hard to tell why this is happening.

Thanks for the reply, AlecTheRegent. Yes, this was a suspicion I had. I saw other cases where that was the issue. I think I will have to create a way to visualize the y force and see if it is building up when it should not be. Thanks for the tip.

If I continue to have trouble I can try to create simplified movement code for testing. I just worry that will take longer than finding the issue itself!

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 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 webmaster@godotengine.org with your username.