How do i flip_h an animation

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

Hello there! Please help!
I ran into this problem. I’m using an animation player with a bunch of different sprites (8 to be exact) and all of the animations go into the animation tree to make walk/jump/etc amimation.
But the little robot is facing right and when I’m walking left and i use Flip_h this way I run into a problem:

func _physics_process(delta):

	if Input.is_action_just_pressed("ui_right"):
		$body.flip_h = false
		get_node("body/head").flip_h =  false
		get_node("body/head/front feather").flip_h =  false
		get_node("body/head/back feather").flip_h =  false
		get_node("body/back arm").flip_h =  false
		get_node("body/front leg").flip_h =  false
		get_node("body/front arm").flip_h =  false
		get_node("body/back leg").flip_h =  false
	elif Input.is_action_just_pressed("ui_left"):
		$body.flip_h = true
		get_node("body/head").flip_h = true
		get_node("body/head/front feather").flip_h = true
		get_node("body/head/back feather").flip_h = true
		get_node("body/back arm").flip_h = true
		get_node("body/front leg").flip_h = true
		get_node("body/front arm").flip_h = true
		get_node("body/back leg").flip_h = true

This is how i flip it probably there’s a better way to do it but…
The problem is that the arms/legs and the pinnk feathers around his head dont flip around their pivot point they just. Look:
image 1
image 2
image 3
image 4

:bust_in_silhouette: Reply From: jgodfrey

Looks like you have a Node2D that contains your entire sprite tree. You could change the scale.x of that node to either1 or -1 depending on the desired facing direction.

Thank you so much! Does scale work like flip or do i have to write $body.scale(1,-1) or smh because I cant seem to get it right

Anastasia | 2020-02-16 16:04

In your image of the scene tree, body looks like a sprite. I’m talking about the Node2D that contains all of the sprites (so, one level higher).

$Node2D.scale.x = -1

… or …

$Node2D.scale.x = 1

depending on which direction you want…

jgodfrey | 2020-02-16 16:09

I also removed everything but the body lines because i dont need em anymore!

Anastasia | 2020-02-16 16:21

Hello! ran into another problem… it works fine while the animation tree is off but while active…
enter link description here
enter link description here
enter link description here
enter link description here

func _physics_process(delta):
if Input.is_action_just_pressed("ui_right"):
	$body.scale.x = 0.246

elif Input.is_action_just_pressed("ui_left"):
	$body.scale.x = -0.246

Anastasia | 2020-02-16 16:35

Most of the links you posted are broken. I’m not sure what the problem is or how the posted code relates…

jgodfrey | 2020-02-16 16:45

srry one sec

Anastasia | 2020-02-16 16:52

Looks like you’re still changing the scale on $body. What happens if you instead change the scale on the containing Node2D (the one containing body)? The obvious difference there would be changing the scale on the Node2D would also have the effect of flipping the AnimationTree and the AnimationPlayer (as they are also children of the Node2D).

As I’ve never tried to the scale-flip trick on some of these components, I’m not sure how they’ll react, but it might be worth a try…

jgodfrey | 2020-02-16 16:58

Invalid get index ‘scale’ (on base: ‘GDScriptNativeClass’)
I get this

Anastasia | 2020-02-16 17:07

Ok ok it does no longer do that. but. it does not longer flip either
heres the kinematic body code

  extends KinematicBody2D

var motion=Vector2()
const UP =Vector2(0, -1)
const GRAVITY = 200
const SPEED = 2000
const JUMP_HEIGHT = -4000
var state_machine 
  

#signal health_ubdated(health)
#signal killed()
func _ready():
	state_machine = $Node2D/AnimationTree.get("parameters/playback")



func _physics_process(delta):
	motion.y +=GRAVITY
	pass
	if Input.is_action_pressed("ui_right"):
		motion.x=SPEED
		state_machine.travel("run right")
	elif Input.is_action_pressed("ui_left"):
		motion.x=-SPEED
		state_machine.travel("run right")
	else:
		motion.x = 0
		state_machine.travel("Idle")
	if is_on_floor():
		if Input.is_action_just_pressed("ui_up"):
			motion.y = JUMP_HEIGHT
	else:
			state_machine.travel("air")
	motion = move_and_slide(motion, UP)

Anastasia | 2020-02-16 17:20