Problem with flipping a collision group on the x axis

I’m making an enemy npc that will hit a wall and then move back in the direction it came from. When implimenting this i want the collision group for the enemies hitbox to change to the other side of the enemy.

So i produced the below code which should flip the collision group on the x axis when the velocity is less than 0 which is caused by the enemy hitting a wall:

	physics.set_hflip("enemy:/enemy#enemy_hitbox", self.movement < 0)

But i got the error:


does anyone know how i could possibly fix this???

The error says it all:

function called can only access instances within the same collection.

"enemy:/enemy#enemy_hitbox" points to the hitbox of an enemy in a game world named “enemy” (which probably doesn’t exist). Assuming the script and the collision object are part of the same object, you can shorten that to "#enemy_hitbox".

1 Like

using the code below worked as it shifted the hitbox:

	physics.set_hflip("#enemy_hitbox", self.movement < 0)

But i know have a problem where the hitbox overlays the movement collision group shown by the screenshot below:
image
Do i know how i could stop the enemy image from being knocked out of the movement collision sphere every time it hits a wall?