The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

–1 vote

i am using god 3.5 windows 10
2D platformer game.
here is my code

enum States {AIR = 1, FLOOR, LADDER, WALL}
var state = States.AIR
var velocity = Vector2(0,0)
var is_jumping = true

const SPEED = 210
const GRAVITY = 35
const JUMPFORCE = -1100

func physicsprocess(delta):
match state:
States.AIR:
if isonfloor():
state = States.FLOOR
continue
$Sprite.play("Air")
if Input.isactionpressed("Right"):
velocity.x = SPEED
$Sprite.fliph = false
elif Input.is
actionpressed("Left"):
velocity.x = SPEED
$Sprite.flip
h = true
else:
velocity.x = lerp(velocity.x,0,0.2)
moveandfall()
States.FLOOR:
if not isonfloor():
state = States.AIR
if Input.isactionpressed("Right"):
velocity.x = SPEED
$Sprite.play("Walk")
$Sprite.fliph = false
elif Input.is
actionpressed("Left"):
velocity.x = -SPEED
$Sprite.play("Walk")
$Sprite.flip
h = true
else:
$Sprite.play("Idle")
velocity.x = lerp(velocity.x, 0,0.2)

            if Input.is_action_just_pressed("Jump"):
                velocity.y = JUMPFORCE
                $SoundJump.play()
                state = States.AIR

            move_and_fall()

func moveandfall():
velocity.y = velocity.y + GRAVITY
var snap = Vector2.DOWN * 32 if !isjumping else Vector2.ZERO
velocity = move
andslidewith_snap(velocity, snap, Vector2.UP)

when I run the level I can walk in both directions and jump straight up
and walk to the right and jump at the same time

but when I try to walk to the left and jump at the same time it jumps me back to the rigt

Godot version 3.5
in Engine by (52 points)

I fixed it
I took out var is_jumping = true and the line

var snap = Vector2.DOWN * 32 if !isjumping else Vector2.ZERO

and changed
velocity = moveandslidewithsnap(velocity, snap, Vector2.UP)
to
velocity = moveandslide(velocity,Vectore2.UP)

and change
elif Input.isactionpressed("Left"):
velocity.x = SPEED

to
elif Input.isactionpressed("Left"):
velocity.x = -SPEED

1 Answer

0 votes

Take out var is_jumping = true and the line

var snap = Vector2.DOWN * 32 if !isjumping else Vector2.ZERO

and change
velocity = moveandslidewithsnap(velocity, snap, Vector2.UP)
to
velocity = moveandslide(velocity,Vectore2.UP)

and change
elif Input.isactionpressed("Left"):
velocity.x = SPEED

to
elif Input.isactionpressed("Left"):
velocity.x = -SPEED

by (1,055 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.