Colliding with nothing (Mostly near corners)

Godot Version

v4.2.1.stable.mono.official [b09f793f5]


I’m having an issue where I am colliding with seemingly nothing. It’s like I’m getting ‘stuck’ on something while walking and I can eventually push through it. It happens the most in corners but can happen anywhere near a wall that does have collision. I can’t tell if the issue lies with the CollisionShape2D that is attached to a CharacterBody2D or with the TileMap collisions. I can’t figure out why this is occurring so any help will be greatly appreciated. :pray:

Example of issue:

Example where issue doesn’t occur:


Here is my movement script that is attached to the character. It’s the only script that is running.

extends CharacterBody2D

var speed = 200
enum Dir { Right, Left, Down, Up }
var direction = Dir.Down

func _physics_process(delta):
	velocity = Vector2()  # Reset velocity each frame

	# Example for player-controlled movement
	if Input.is_action_pressed('ui_right'):
		velocity.x += 1
		direction = Dir.Right
	if Input.is_action_pressed('ui_left'):
		velocity.x -= 1
		direction = Dir.Left
	if Input.is_action_pressed('ui_down'):
		velocity.y += 1
		direction = Dir.Down
	if Input.is_action_pressed('ui_up'):
		velocity.y -= 1
		direction = Dir.Up

	velocity = velocity.normalized() * speed

	# Update sprite frame based on direction

func update_sprite_frame():
	if velocity.x == 0 and velocity.y == 0:
		$"_" + Dir.keys()[direction])
		$"Walk" + Dir.keys()[direction])

I’ve verified that a collision IS being detected by the CharacterBody2D by adding the following code to the movement script. Still, the ‘Visible Collision Shapes’ that can be seen in the videos I shared indicate that they shouldn’t be colliding… and I’m not sure why they are.

var collision = get_last_slide_collision()
	if collision:
		var collider = collision.get_collider()

I’ve figured out what the issue was… and it’s rather obvious in hindsight. I had another character with the same movement script attached to them. Their node was ‘hidden’ but they still moved around. Thus, I was actually colliding with the invisible character. My previous comment indicated I was colliding with the TileMap because I was seeing the print output of the invisible character. By deleting the invisible character node, the issue went away - so this issue is resolved! :tada:

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