0 votes

I think i already asked this but i couldn't fint the thread so sorry if im spamming.

My character scales only one way. I have it so that he scales right when he goes right (-1) and scales left when he goes left (1). But for some weird reason when he is turned right and i press left he doesn't turn left. Idk why that is but I think when he changes scale to -1 that scale is now 1 so when he is supposed to turn left he doesn't, and when he is supposed to sill face right he then turns left. Idk how to explain it better.

Here is the script:
extends KinematicBody2D

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

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"):
    $Sprite/atak.play("atak")
if Input.is_action_just_pressed("left"):
    scale.x = abs(1)
if Input.is_action_just_pressed("right"):
    scale.x = -1
Godot version Godot v3.2.3 - stable
in Engine by (14 points)

What does your sprite look like? Is it facing left by default?

My sprite is just a dude. He is facing left by default. On the inspector its scale is x:1 y:1.

1 Answer

0 votes

I dont know what the abs() function does because i've never used it before but i've made a 2D platformer before and i just set scale.x as either 1 or -1 depending on keyboard input and it works without any bugs, i honestly dont see the cause of your problem either and if the bug remains i apologize for not being much help

by (60 points)

abs() is absolute value and doesn't seem to have any use in the function.

Do you have the scale change under func physics process or some other function? Because I also did it under _func _unhandledinput and it worked the exact same way.

I divide my code into functions so anything input related i put in a function i named "inputs" and called it under _physics process, i set it so that if the a key is pressed it will set scale.x into 1 repeatedly so that it cant change into any other value since its being set every frame if the a key is pressed, same goes for d key

Could you copy paste the line of code here or if you were following a tutorial could you give me a link? Because when i put it under physicsprocess it just keeps jitterng when i hold d but when i hold a it doesn't do anything.
My only guess is its multiplying the value of the scale, but i didn't ever tell it to do that.

I've deleted the project way back then but essentially it went aomething like this

func UserInput():
    if Input.is_action_pressed("left"):
        scale.x = 1
    elif Input.is_action_pressed("right"):
        scale.x = -1

func _physics_process(delta):
    UserInput()

If the bug remains then i dont even know anymore

Edit: wait wait wait maybe its got something to do with the fact that you're using isactionjust_pressed, that line will return true once and will only return false until the key is lifted and pressed again but hey i dont know im on my phone cant really test it

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.