Player character gets stuck at corners (2d, isometric)

Godot 4.4.1

Question

Hi, I managed to get a (more or less) correct collision with a CollisionPolygon2D as a child to a StaticBody2D.

When the Player walks straight against diagonal lines, the chara glides along the collision border. But once she arrives at the corner, the character gets stuck. Only way out is to change the direction away from the collision mesh.

I tried to fix it by making the corners a bit “rounder” by using several points instead of just a single one - but still, same result.

Does anyone know a simple way to fix that?

Hi, are you using a CharacterBody2D as the player? Can you post the relevant movement code?

I use the “Player” node thats listed within the “CharaterBody2D” when selecting the node type.

The code:


(the transparent stuff is only for adjusting move speed and animation)

The code as text:
var vMoveDirection: Vector2 = Vector2.ZERO # the real physical movement
var vMoveSpeed: int = 300
var vRunSpeed: int = 620

...

func _ready():                  #standard, called, when node enters scene first time
	pass                        #ends function if empty
	
func _process ( delta ):       #standard, called every frame. "delta"= time since previous frame
	#===== MOVEMENT =====
	vMoveDirection.x = Input.get_action_strength("MoveRight") - Input.get_action_strength("MoveLeft")
	vMoveDirection.y = (Input.get_action_strength("MoveDown") - Input.get_action_strength("MoveUp"))/2
	#===== MOVEMENT SPEED  ========
	# Walk or Run?
	if Input.is_action_pressed("Run"): 
		velocity = vMoveDirection * vRunSpeed
	else: velocity = vMoveDirection * vMoveSpeed

...

func _physics_process( _delta ):    # standard, needed for movement
	move_and_slide()

...

func fIsDiagonalMovement()-> bool:
	if vMoveDirection.x != 0 and vMoveDirection.y != 0:
		return true
	else:
		return false

Try setting the CharacterBody2D.motion_mode to Floating

1 Like

Thanks :slight_smile:
Setting the motion mode to floating worked for the corners, but when walking against a corner I get this weird glitch now (was maybe before too, but not visible because the character was stuck):


It looks like the game wants to let the character slide, but cannot decide in what direction :joy:

You may need to tweak the shapes to avoid that, I’m not sure.

1 Like

Okay, I found the solution:
I have to make the problem corners really round


then it works woth “floating” like intended.

EDIT: And I have to set the"Wall min slide" to a really low value and I cant use any lines that are exactly in a 90° angle to the character movement. There needs to be at least small difference, so the game knows in which direction the character has to slide.

Thanks again for that tip :slight_smile: