The child of the instanced scene is not flipping the sprite.

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

heres a link to the video.

The weapon is an inheritable scene that is inherited by other weapons. They all have the code to flip the sprite image horizontally towards to the direction of the mouse from the player body. It also has the code that allows it to move around the player which works well but for some reason the flip doesnt work when it is instanced by the player but when played as just the scene (F6) it works properly as seen from the start of the video.

my bad, newbie here sorry, here’s the code for the player spawning the weapons.
extends KinematicBody2D

const BASED_MOVEMENT_SPEED = 10 * 16

var desired_velocity = Vector2.ZERO
var velocity = Vector2.ZERO
var direction = Vector2.ZERO
var weight = 0.3
var weapon_change = "sword";
var weapons: = {
	sword = preload("res://Scenes/Weapon.tscn"),
	rock  = preload("res://Scenes/Rock.tscn"),
	claw  = preload("res://Scenes/Claw.tscn")

onready var target = Vector2.ZERO
onready var weapon_position = $weapon_manager

func _process(delta):
func _weapon_change():
	if (Input.is_action_just_pressed("Switch_Item1")):
		weapon_change = "sword"
	elif (Input.is_action_just_pressed("Switch_Item2")):
		weapon_change = "rock"
	elif (Input.is_action_just_pressed("Switch_Item3")):
		weapon_change = "claw"

func _movement_input():
	direction =  Vector2.ZERO
	direction.x = -int(Input.is_action_pressed("ui_left")) + int(Input.is_action_pressed("ui_right"))
	direction.y = -int(Input.is_action_pressed("ui_up")) + int(Input.is_action_pressed("ui_down"))
	desired_velocity = direction.normalized() * BASED_MOVEMENT_SPEED
	velocity = velocity.linear_interpolate(desired_velocity, weight)
	velocity = move_and_slide(velocity)
func _weapon_movement():
	for weapon in weapon_position.get_children():
	var weapon_instance = weapons[weapon_change].instance()
	target = get_global_mouse_position()

And Here’s the script for the weapon that is instanced by the player

    extends Node2D

onready var target = Vector2.ZERO
# Called when the node enters the scene tree for the first time.
func _process(delta):
	target = get_global_mouse_position()
	if target.x > self.position.x:
	elif target.x < self.position.x:
:bust_in_silhouette: Reply From: Inces

You should better post your code instead of videos :slight_smile:
Show at least code of flipping in weapon class and code of moving around the player

my bad, i just added the code to the original question.

ckxsl023 | 2021-03-28 03:01

I think I can seen what is going on
Weapon_movement() function is in process(), every frame You create instance, add child and remove it. What we see in video is not one weapon, but thousands of weapons being created and destroyed in a blink, so the inherited code to flip sprite according to mouse position never happens.

You need to move lines of code with removing weapons, creating instance and adding child into weapon_change() function, and only leave lines about look_at() in weapon_movement().

Also You don’t have to check for input in process(), there is a built-in input(event) function, and it should be enough for your weapon_change()

Inces | 2021-03-28 07:08