The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+2 votes

Here is my code:

if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
    motion.x = 0
elif Input.is_action_pressed("ui_right"):
    motion.x = SPEED * delta
    sprite_node.set_flip_h(false)
elif Input.is_action_pressed("ui_left"):
    motion.x = -SPEED * delta
    sprite_node.set_flip_h(true)
else: motion.x = lerp (motion.x,0,0.75)

I have also tried

Godot version 3.2.3.stable
in Engine by (61 points)

Are you trying to flip horizontally or vertically?

horizontally, I am making a platformer

2 Answers

0 votes
Best answer

Maybe I'm late.

To flip any node horizontally, set the scale property to Vector2(-1, 1)
Vertically: Vector2(1, -1)

Example: I want to flip my sprite and collisionShape2D horizontally:

var flip = Vector2(-1,1)
$<sprite_name>.scale = flip
$<collisionShape2D_name>.scale = flip

If you use a scale for scaling objects then you'd have to set the value relatively I guess

Altought this won't work for Node2D, for that you'd have to instance that Node2D as a child inside another Node2D using it as an anchor, then flip the parent (anchor)
Image (somewhy it wont appear here): https://drive.google.com/uc?export=view&id=1QmPG2g99J2CvkrdVr5pCOdiciRnHHl8J

SIMPLE AND QUICKER SOLUTION: If you want to stay outta all those trouble you can just flip the whole player node instead.

by (63 points)
edited by
0 votes

You can try

self.rotation_degrees = 180 

to flip the entire Node (and its childrens)

by (450 points)

This makes the player upside down

Oops, yes you are right. Dont know then

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 Frequently asked questions and 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 [email protected] with your username.