0 votes

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

in Projects by (63 points)

1 Answer

0 votes
Best answer

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.

by (9,140 points)
selected by

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

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...

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

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

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

srry one sec

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...

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

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)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories