Changing a sprite when said sprite is inside a resource

Godot Version 4.7 stable

Hello there, my name is Markiplier and welcome to your biweekly show of “How Do I Code This?” in today’s episode, I have a weapon resource for making different weapons (guns) and now that I´m implementing them (instantiating them through a weapon controller component) I want to flip the sprites of said resources (guns) according to the position of the mouse cursor relative to the character.

when the mouse.global_position.x > the player, it looks like this

and yet, when is not, looks like this:

I’m instantiating the weapon through this weapon controller:

class_name WeaponController extends Node

@export var current_weapon: WeaponGeneral
@export var weapon_model_parent: Node2D
var current_weapon_model: Node2D

func _ready():
if current_weapon:
spawn_weapon_model()

func spawn_weapon_model():
if current_weapon_model:
current_weapon_model.queue_free()

if current_weapon.weapon_model:
	current_weapon_model = current_weapon.weapon_model.instantiate()
	weapon_model_parent.add_child(current_weapon_model)
	current_weapon_model.position = current_weapon.weapon_position

attached to a marker in the arm sprite:

class_name QuackyMainScript extends CharacterBody2D
@onready var weapon_controller = $WeaponController
@export  var Body: Sprite2D
@export  var Arm:  Sprite2D

var mouse_position = get_global_mouse_position()

func _physics_process(delta:float) -> void:
Arm.look_at(mouse_position)
Arm.rotation += deg_to_rad(270)


#flips the sprite so tat it looks normal
if Body.global_position.x < mouse_position.x:
	Body.flip_h = true
	
else:
	Body.flip_h = false

here is my tree scene:

Quacky
┠╴Body
┃ ┖╴Arm
┃ ┖╴Gun marker
┃ ┖╴BasicPistol
┃ ┖╴Pistol Sprite
┠╴CollisionHead
┠╴CollisionBody
┠╴HitboxBody
┃ ┖╴DetectionForHitBody
┠╴HitboxHead
┃ ┖╴DetectionForHitHead
┠╴HitboxTail
┃ ┖╴DetectionForHitTail
┖╴WeaponController

So, I want to know how to fix this sprite, called using a component, from a gun resource

You probably want to flip_v the gun in certain instances, such as the rotation being >180°

Is your weapon model scene a Sprite2D or AnimatedSprite2D? If so you could use the current_weapon_model variable directly.

Yeah so, the problem I’m having is that I put a packed scene as the model of the gun, my packed scene is only a Node2D and a Sprite, so anytime im trying to apply flip_v or flip_h this error appears:

E 0:00:13:110 QuackyMainScript._physics_process: Invalid assignment of property or key ‘flip_v’ with value of type ‘bool’ on a base object of type ‘Node2D’.
Quacky_Main_Script.gd:31 @ QuackyMainScript._physics_process()
Quacky_Main_Script.gd:31 @ _physics_process()

Is there any reason you cannot make the Sprite the root of your packed scene?

Now that I think about it, there is none, so Ill change it and see if this changes it.

Indeed, that solved it. making the parent node of the scene a Sprite or AnimatedSprite allowed me to manipulate the flip call. so now no matter where I’m pointing, the gun remains upright. Thank you!