This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I have an area2d child for my kinematicbody 2d as my attackbox and i want it to flip when the player flips.

in Engine by (401 points)

4 Answers

0 votes

If you use scale.x *= -1 on the KinematicBody2D, its children will be flipped as well.

by (22,191 points)

I tried that but for some reason my player keeps flipping back and forth if i try to move left.

Well that's the answer. Since you didn't show what you did, I can't tell you what you did wrong.

No it's not the answer. Kinematic bodies cannot be flipped that easily.

I tried that but for some reason my player keeps flipping back and forth if i try to move left.

that's because you are flipping it once every frame.

0 votes

Pseudo code:

if is_moving_left:
    scale.x = -1
elif is_moving_right:
    scale.x = 1
by (4,246 points)
0 votes
if _velocity.y < 0:
    scale.x = scale.y * -1
elif _velocity.y > 0:
    scale.x = scale.y * 1

This also keeps the body from flipping.


by (60 points)
0 votes

I was struggler to flip my kinematic body, but i found to manage to be able to doing it the rigth way with all the answers i read.

enter image description here

onready var animated_sprite = $AnimatedSprite
onready var melee_weapon = $Hitbox

if velocity.x > 0:
    melee_weapon.scale.x = 1
    animated_sprite.flip_h = false
elif velocity.x < 0:
    melee_weapon.scale.x = -1
    animated_sprite.flip_h = true

and that work for me.

If i understand, moveandslide() reset each frame scale.x to 1. Im not sure but i seem to read somewhere this reason for the flickering.

My first answer, yeah :D

by (18 points)
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.