0 votes

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 physicsprocess(_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"):
if Input.is_action_just_pressed("left"):
    _scale1 = Vector2(1,1)
if Input.is_action_just_pressed("right"):
    _scale1 = Vector2(-1,1)

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

Godot version Godot v3.2.3 - stable
in Engine by (14 points)

1 Answer

0 votes

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)


scale = Vector2(1, 1)

or even

scale.x = -1
by (18,963 points)

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.

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.