When i change my players scale to -1 the collision box doesnt fit anymore

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gedzi752

This is my 2nd day using godot and making games in general. I took some movement code from a video on yt and made a single sprite for my character (not animated, for now) and it moves okay but when i turn left the sprite changes its scale to -1 and so does the collision box (probably) but the collision box goes out of the character to the right so an arm goes through tiles. I tried to find an answer but i couldnt find anything thats why i created an account here to ask.

here is the script:

 extends KinematicBody2D

const GRAVITY = 35
const JUMP_FORCE = 550
const SPEED = 300
const ACCEL = 0.4
const MAXACCEL = 800

onready var sprite = $Sprite

var velocity = Vector2.ZERO

func _unhandled_input(event):
	if event.is_action_pressed("jump") && is_on_floor():
		velocity.y = -JUMP_FORCE	

func _physics_process(_delta):
	velocity.y += GRAVITY
	if velocity.y > MAXACCEL:
		velocity.y = MAXACCEL
	
	var dir = Input.get_action_strength("right") - Input.get_action_strength("left")
	if dir != 0:
		sprite.scale.x = dir
	
	velocity.x = lerp(velocity.x, SPEED * dir, ACCEL)
	velocity = move_and_slide(velocity, Vector2.UP)
:bust_in_silhouette: Reply From: Merlin1846

Your tree should look like this.

-KinematicBody2d
–CollisionShape2d
–Sprite

When you want to flip your sprite do.

$sprite.scale.x = -1

If your CollisionShape2d is asymmetric then do this instead.

-KinematicBody2d
–CollisionShape2d
—Sprite

$CollisionShape2d.scale.x = -1