I'm new to Godot (and computer programming in general), and to sharpen my skills I decided to try and make a simply 2D platforming game. The player is a KinematicBody2D. I made some tile sprites for a TileMap, and gave each tile the correct collision boxes (I think). I coded my player to move and jump with this:
#gravity and jumping
if is_on_floor() == true:
if Input.is_action_just_pressed("ui_up"):
velocity.y = JUMP_POWER
else:
velocity.y += GRAVITY
if is_on_ceiling() == true:
velocity.y += 30
#collision testing
if is_on_floor() == true:
if is_on_wall() == true:
print("wall and floor")
else:
print("floor")
elif is_on_wall() == true:
print("wall")
#left and right movement
if Input.is_action_pressed("ui_left") == true:
velocity.x = -SPEED
elif Input.is_action_pressed("ui_right") == true:
velocity.x = SPEED
else:
velocity.x = 0
Extending KinematicBody2D, the code above is the contents of a function that I ran inside _physics_process()
, and then I used `moveandslide(velocity, Vector2(0,-1), true)' to make everything work.
The problem I have is that when I'm controlling my player and I walk into walls, it seems to sort of glitch into the wall at an angle downward. When this happens, the jumping functions are a little hit or miss. Now, you may have noticed my that I've got a section of code above that I put a comment above calling it "collision testing". It'll just test if its colliding properly. Running this code while I'm colliding into the wall and making it glitch into the corner gives me this console output:
wall and floor
wall
wall and floor
wall
wall and floor
... and so on. This tells me that my jumping mechanics are bad in the corner because Its only sometimes detecting my player as touching the floor. There's something wrong here, and I hope its something wrong with my code. Can anyone help me make collisions work smoother? Here's a few images of my setup:


TLDR my collision is wacky, and when I walk into a corner it only detects that I'm colliding with both the wall and the floor every other frame. Every frame in between, it just thinks I'm colliding with the wall and nothing else. My jumping mechanics are tied to whether or not the player is on the ground, so when this happens its literally a 50-50 chance of working. Help?