|Topic was automatically imported from the old Question2Answer platform.
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 2D Platformer Demo (KinematicBody) - Godot Asset Library.
Tileset and character by penusbmic (Free Dungeon Ruins Tileset by Penusbmic).
For me it looks like your code does not reset y-“impulse” at all cases. Your implementation of falling probably looks like
impulse.y += gravity
if is_on_floor(): # I think this check is failing in some cases
impulse.y = 0.0
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.
AlexTheRegent | 2021-07-22 15:24
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!
fizzyted | 2021-07-22 15:30