How do I flip Light2D horizontally along with the rest of it's parent node

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

Hello, I’d like to know how I can flip a light2D node that I’m using as a flashlight for my 2d character.
I can’t seem to find any explanations online on how I would go about this. My player script looks like this:

extends KinematicBody2D

var SPEED = 200
const GRAVITY = 20
const JUMP_POWER = -200
const FLOOR = Vector2(0, -1)
const TURNTIME = 0.1
const BASED_SPEED = 200

var velocity = Vector2()

var moving_right


var on_ground

func _physics_process(delta):

	if Input.is_action_pressed("ui_shift"):
		SPEED = 450
	if Input.is_action_just_released("ui_shift"):
		SPEED = BASED_SPEED

#Basic Movement
	
	if Input.is_action_pressed("ui_right"):
		velocity.x = SPEED
		moving_right = true
		$AnimatedSprite.flip_h = true

	elif Input.is_action_pressed("ui_left"):
		velocity.x = -SPEED
		moving_right = false
		$AnimatedSprite.flip_h = false
		
	else:
		velocity.x = 0
	
	if Input.is_action_pressed("ui_up"):
		if on_ground == true:
			velocity.y = JUMP_POWER
			on_ground = false
	velocity.y = velocity.y + GRAVITY
	
	
	if is_on_floor():
		on_ground = true
	else:
		on_ground = false
	
	
	velocity = move_and_slide(velocity, FLOOR)

I have my nodes as follows

KinematicBody2D

  • Light2D
  • AnimatedSprite
  • LightOccluder2D
  • CollisionShape2D

I am quite new to Godot and I for the life of can’t figure out how to rotate everything.

I tried using

apply_scale(Vector2(-1, 1))

once but it just made my character spin out of control.

Any solutions or improvements would be much appreciated.

:bust_in_silhouette: Reply From: Tato64

Make the light a child of the animatedsprite (This is not 100% necessary but it’s convenient)

Remove the $AnimatedSprite.flip_h lines in your Input.is_action_presseds

Then add this somewhere in your _physics_process:

if velocity.x > 0:
     $AnimatedSprite.scale = Vector2(1,1)
elif: velocity.x < 0:
     $AnimatedSprite.scale = Vector2(-1,1)

Let me know how it goes!