Flip Character new Input System

Godot Version

4.3.stable.official

Question

Hi team new to Godot from Unity (Visual Scripting) have not code in a long time but trying to get back. Trying to flip my character when pressing “ui_left” since I am new so don’t know where I could add that function to flip the character. Here is the script so far.

I am not sure what you want, but you can try this in physics process:

if direction: scale.x = lerpf(scale.x, (1 if direction.x > 0 else -1), delta * 10.0)

Gdscript is not hard, just I like to code like this, here I used termary operation for short.
There is only one issue with this code, but if you found it big then you can let me know.

1 Like

Thank you so much!! That was fast lol!!! Well i am doing a 2d beat em up game (currently using streets of rage 4 character has place holders until I get mine done)

All so far I want to do is flip the character when pressing left then flip back when pressing right! I will make a process apart for physics thanks for this!!! I got the movement left right etc on the script that I attached.

Will try the scale.x is that a parameter already in Gdscript?

Thanks in advance!!

2 Likes

Hey wanted to let you know!! I did it this is how I did it.

1 Like

Oh I misterunderstood your question, I thought that you want to flip your character with a smooth transition (actually I was working on it), your codes is ok but you can do it by one line only:

var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
velocity = direction * speed
move_and_slide()

adam_animated_sprite.flip_h = true if direction.x < 0 else false

The codes I provided is the movement of player and the flipping of sprite based on movement. I am not sure how you done this by “move” variable, but the above codes are the correct and short for the movement, you can try this instead of yours.

1 Like

Thanks!!! Yeah that is waayyy simpler than what I did hahaha!!! I got the animarions running for walking up, down, left and right!!!

Setting up now the colliders so the character does not go past the screen lol!
And jumping! Hahaha

There is a lot to go!! Health bars, attacking enemy AI!!! But pumped!!!

Thanks I really appreciate all your help man!!!

1 Like

Hi King!!

So last night I worked on the code a little before seeing your response this is what I got back and is working with animation also. Now unto jumping and attacking!!!

also setting up colliders for character boundry.

1 Like

sorry to keep bothering just exited about my progress!! added the move and slide for the colliders to work look!! haha. Without you could not get the boundaries without that move and slide.

1 Like

There is nothing to apologize.

I have some questions,
Why are you changing the position instead of set the velocity of character body?
Also your codes are too long, you could short and clean them.

Got no idea hahahaha! Noob here lol!!! What could be the best practice? I already have the variables etc set for that code. I am using streets of rage 4 Adam has a place holder for the Main Character. I can send you a video of what I already got if needed IDK.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.