CharacterBody2D getting stuck when walking over two other characterbodies

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

Hi, I’ve been trying the engine so far, but I’m currently facing a scenario where my char gets stuck over other collision bodies.

See the sample picture below, I’m trying to make my player body walk over the other two player bodies, the “dinos” have two collision boxes the bigger one is disabled when the “dino” is crouched and the yellow one is currently active when I try to move the position x of the char it does not work the player needs to go back to the other direction and try again, I’ve been trying to identify why this is happening but not working so far.

Please note that the player character is using a CollisionPolygon2D but the same issue happens with a regular CollisionShape2D.

image

Below the code used to move the player

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

	move_and_slide()
	
	var isLeft = velocity.x < 0
	sprite_2d.flip_h = isLeft

Small update, I thought the issue could be related to the collision box not flipping to the left when changing directions, I’ve fixed that but the issue is still there.

image

Well, the issue was not changing the collision box direction it didn’t work the first time because one of the legs was slighter bigger on the collision box.

So fixing both issues solved the problem.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.