How do i flip my hitboxes?

Godot Version 4.4.1

Question

I’m making a small hollow knight fangame, and i’m now making the ability to attack. But i have a complicated CollisionPolygon2D. Is there a way to flip it when i’m moving left?

(the complicated polygon itself)

also here’s my character code:

extends CharacterBody2D
@export var move_speed := 100.0
@export var jump_velocity := -360.0
@export var gravity := 900.0
@export var jump_cut_multiplier := 0.1
var was_on_floor := false
@onready var animation := $AnimationPlayer

func _physics_process(delta):if not is_on_floor():velocity.y += gravity * delta

var direction := Input.get_axis("Goleft", "Goright")
velocity.x = direction * move_speed

if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = jump_velocity
	animation.play("jump")

if Input.is_action_just_released("jump") and velocity.y < 0:
	velocity.y *= jump_cut_multiplier


handle_animations(direction)

if not was_on_floor and is_on_floor():
	animation.play("land")

was_on_floor = is_on_floor()

move_and_slide()
func handle_animations(direction):
if not is_on_floor():
if velocity.y < 0:
animation.play(“jump”)
elif not was_on_floor and is_on_floor():
animation.play(“fall”)
else:
if direction != 0:
animation.play(“walk”)
else:
animation.play(“idle”)
if direction != 0:
$Sprite2D.flip_h = direction < 0```

(i have no idea why it split)

You might be able to flip the collision shape by scaling negative one on the X axis.

2 Likes

it actually works! I just need to change the x position to it’s minus. Thank you

make sure to test with collisions too, I know collision data does not like non-uniform scaling and may behave strangely. I don’t think negative 1 counts as uniform, but good luck

1 Like