# Vertical scale changes in a weird manner.

Attention Topic was automatically imported from the old Question2Answer platform.
Asked By Youbadass

I tried to make it so my character turns right when I tell him to go right, but for some weird reason he changes his vertical scale. I even tried to make it so when the vertical scale is -1 to set it to 1 but then it conflicts with something else and he just does some weird stuff.
Heres the code:

extends KinematicBody2D

var velocity = Vector2(0,0)
const SPEED = 180
var jumpforce = -800
const gravity = 30
var _scale1 = Vector2(1,1)

func _physics_process(_delta):

``````if Input.is_action_pressed("right"):
velocity.x = SPEED

if Input.is_action_pressed("left"):
velocity.x = -SPEED

velocity.y = velocity.y + gravity

if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jumpforce
if Input.is_action_just_pressed("atak 2"):
\$Sprite/atak.play("atak dzida")
velocity = move_and_slide(velocity,Vector2.UP)

velocity.x = lerp(velocity.x,0,0.5)

if Input.is_action_just_pressed("atak"):
\$Sprite/atak.play("atak")
if Input.is_action_just_pressed("left"):
_scale1 = Vector2(1,1)
set_scale(_scale1)
if Input.is_action_just_pressed("right"):
_scale1 = Vector2(-1,1)
set_scale(_scale1)
``````

I don’t get any errors so idk what is going on.

Reply From: kidscancode

I don’t see anything in the code here that would do anything with the vertical scale. Is your sprite perhaps rotated or scaled separately from the KinematicBody? Is your initial scale in the Inspector set to a value other than (1, 1)?

BTW, you can just set the scale property directly. You can replace

``````_scale1 = Vector2(1, 1)
set_scale(_scale1)
``````

with:

``````scale = Vector2(1, 1)
``````

or even

``````scale.x = -1
``````

I replaced the scale stuff just like you told me to and it kinda works now, but now he only flips directions when i press d (right) . When i press a (left) he doesn’t change direction. Idk why it’s like that. When I fire my project up my character is turned left, when I press d (right) he turns around and he is now facing right. When i press a (left) he doesn’t turn around, he just slides to the left. When i press d (right) again he turns left but goes right.
Sorry for my bad english.

Youbadass | 2021-02-28 10:11

Reply From: Hyper Sonic

To sum up, scale.x = -1 is converted into scale.y = -1 and rotation_degrees = 180, but scale.x remains 1 internally, so next time you set scale.x = -1, it will try to flip again.

In your case, you set both scale.x and scale.y, so scale.x = -1 is converted into scale.y = -1 & rotation_degrees = 180, but since you immediately set back scale.y = 1, your character becomes upside down with the remaining rotation. So you get flickering like the other answer, but in your case it’s upside down flickering, not just flipping.