Player getting stuck on tilemaplayer collision shape

I am making a simple 2d platformer to learn godot, and am having an issue with the tilemap layer. I just wanted to use the tiles to more easily paint my level, but I am literally only using a black square repeated over and over as ground so there may be a better. The issue, however, is the collision shapes on the tile are quite janky (even though its a black square and they should be done automatically), and the player constantly gets stuck on walls or on the floor.

I made a temporary fix where I just use a staticbody and a collisionshape, but I want to make a lot of terrain and need a fix for the tiles. I have also tried turning up the safe margin for collisions, but by the time I get it to a point where there are no longer glitches the player is so far away from the wall it doesn’t even look like they are touching it (about 20px).

If you have any ideas how to fix it would be so much help, thank you!

Show the collision shapes by enabling Debug > Visible Collision Shapes, and post your movement code.

My code is kinda crap so sorry :sweat_smile:

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@onready var left_ray: RayCast2D = $raycasts/left_ray
@onready var right_ray: RayCast2D = $raycasts/right_ray
@export var wall_x_force = 300.0
@export var wall_y_force = -450.0
var is_wall_jumping = false
var just_wall_jumped = false

var wall_slide = 120

func _physics_process(delta: float) -> void:
	
	wall_logic()

	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta
		
	# Handle jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		if is_on_wall():
			wall_jumping()


	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	if just_wall_jumped == false:
		var direction := Input.get_axis("left", "right")
		if direction:
			velocity.x = direction * SPEED
		else:
			velocity.x = move_toward(velocity.x, 0, SPEED)


	move_and_slide()


func wall_logic():
	if is_on_wall_only() and just_wall_jumped == false:
		#velocity.y = wall_slide #variable determining speed to slide down on wall
		if Input.is_action_just_pressed("jump"):
			if left_ray.is_colliding():
				velocity = Vector2(wall_x_force, wall_y_force)
				wall_jumping()
			if right_ray.is_colliding():
				velocity = Vector2(-wall_x_force, wall_y_force)
				wall_jumping()

func wall_jumping():
	var is_wall_jumping = true
	just_wall_jumped = true
	await get_tree().create_timer(.2).timeout
	is_wall_jumping = false
	just_wall_jumped = false

What happens with jankyness if you don’t call wall_logic()?

Also, you await in a perpetual callback. Don’t do that.

Wall jumping doesn’t work anymore, the wall/floor clipping is still an issue though.

What happens when you get rid of that await?

Yeah the jank is still there, I’ll work on another for my way for my walljump to work without the ‘await’ but that’s a separate issue

Can you post a video or a minimal reproduction project?

I made the minimal reproduction project, how can I share it?
One thing I realized while making this is the default safe margin fixes the floor jankyness, but the wall issue persists.

I think you can just attach a zip to a post. Don’t forget to delete .godot directory before packing it.

Not able to unfortunately, I posted it on itch.io, its having issues today but here is the link if you can get it
https://pg22.itch.io/wall-jump-bug

Always delete .godot directory when posting projects. Seems you deleted the project file instead, which has .godot extension. The project cannot be opened without the project file, but .godot directory contains only temp files specific to your local machine that Godot re-creates if they’re not there.

Alright I deleted only the .godot folder this time, try downloading again

Set character body safe_margin to zero or use a rectangular collider.

2 Likes