How do I flip my sprite but also the CollishionShape2d and the Node2d as a bullet spawn point?

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

Here is my code:

if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
	motion.x = 0
elif Input.is_action_pressed("ui_right"):
	motion.x = SPEED * delta
elif Input.is_action_pressed("ui_left"):
	motion.x = -SPEED * delta
else: motion.x = lerp (motion.x,0,0.75)

I have also tried

Are you trying to flip horizontally or vertically?

spoicat | 2021-05-23 02:07

horizontally, I am making a platformer

antoniodev | 2021-05-23 12:37

:bust_in_silhouette: Reply From: Pomelo

You can try

self.rotation_degrees = 180 

to flip the entire Node (and its childrens)

This makes the player upside down

antoniodev | 2021-05-22 20:42

Oops, yes you are right. Dont know then

Pomelo | 2021-05-22 23:49

:bust_in_silhouette: Reply From: spoicat

Maybe I’m late.

To flip any node horizontally, set the scale property to Vector2(-1, 1)
Vertically: Vector2(1, -1)

Example: I want to flip my sprite and collisionShape2D horizontally:

var flip = Vector2(-1,1)
$<sprite_name>.scale = flip
$<collisionShape2D_name>.scale = flip

If you use a scale for scaling objects then you’d have to set the value relatively I guess

Altought this won’t work for Node2D, for that you’d have to instance that Node2D as a child inside another Node2D using it as an anchor, then flip the parent (anchor)
Image (somewhy it wont appear here):

SIMPLE AND QUICKER SOLUTION: If you want to stay outta all those trouble you can just flip the whole player node instead.