Having issues flipping the sprite of my rocket to face the right direction when player turns left and shoots.

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

My character can shoot rockets and they travel in the right direction depending on what direction my player is facing but the sprite refuses to flip_h when shooting left and it looks like the rocket is traveling backways.

Just trying to understand where I need to put my code to make the rocket sprite flip_h depending on what direction my player is facing and what code specifically I would need to write.

I am a noob, sorry if it sounds like a basic question, I am not very good yet, I am trying to understand though!

Character rocket code:

var direction = 1
const FIRE = preload(“res://Fire.tscn”)

func shoot():
if Input.is_action_just_pressed(“fire”) and not is_near_wall():
var direction = 1 if not $Sprite.flip_h else -1
var f = FIRE.instance()
f.direction = direction
get_parent().add_child(f)
f.position.y = position.y
f.position.x = position.x + 30 * direction

Rocket code:

extends KinematicBody2D

var velocity = Vector2()
var direction = 1
const SPEED = 800
const GRAVITY = 3
const BOUNCE = -300

func _ready():
velocity.x = SPEED * direction

func _physics_process(delta):
velocity.y += GRAVITY

if  is_on_wall():
	queue_free()

velocity = move_and_slide(velocity,Vector2.UP)

func _on_VisibilityNotifier2D_screen_exited():
queue_free()

func _on_Timer_timeout():
$AudioStreamPlayer.play()

:bust_in_silhouette: Reply From: pokemonleafgreen

You could have a system where depending on what key is pressed, the rotation degrees of the node change to face the direction. Like up is 0, down is -180, right is 90, and left is 270. You’d have to set the “up, down, left, right” in the Project Settings under Input Map.
if Input.is_action_pressed("up"): motion.y -= 1 $Rocket.rotation_degrees = 0 if Input.is_action_pressed("down"): motion.y += 1 $Rocket.rotation_degrees = -180
and so on.
I’m also a beginner, so sorry if this is totally off lol.