–1 vote

my code:

func physicsprocess(delta):
var motion = Vector2()
motion = moveandslide(motion, Vector2.UP)
velocity.y += gravity * delta
if Input.isactionpressed("uiright"):
motion.x = 400
elif Input.is
actionpressed("uileft"):
motion.x = -400
elif Input.isactionpressed("jump") and isonfloor():
motion.y = -8000
else:
motion.x = 0
motion.y = 0
gravity = 400
moveandslide(motion)

cos my jump teleports me to the air then slowly falls down

in Engine by (16 points)

2 Answers

0 votes

Bring motion.y back to the gravity amount gradually from a lower value.

elif Input.is_action_pressed("jump") and is_on_floor():
    motion.y = -800 #lower value
    var lerp_amount = 0.0
    while lerp_amount < 1:
        lerp_amount += delta
        motion.y = lerp(-800, gravity, lerp_amount)
        yield(get_tree(), "idle_frame")
by (3,239 points)
0 votes

Your answer is right there in front of you, your jump is jerky but your fall isn't. What's the difference between the way you implement those two features?

TLDT: Your falling is implemented with an acceleration but your jumping is implemented by instantly setting the velocity. So come up with some jump_acceleration and a max_jump_speed (probably -8000 based on your code) and implement a process very similar to what you're doing with gravity except capping the max speed (which you probably want in the opposite direction for gravity as well, depending on how far the character can fall and how high your gravity is)

by (91 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.