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!
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
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.
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.