This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–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

+1 vote

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,259 points)

Thank you!

I'd like to add that after I used this code in mine, my character seemed to have a unintended delay/cooldown on his jump.

I think is_on_floor() wasn't being updated on time because the while loop was slowing the code by waiting the condition to end.

And my character reached the ground before the loop was done.

Writing this on the next line afteryield() fixed it.

if is_on_floor():
    break

Resulting in

while lerp_amount < 1:
    lerp_amount += delta
    motion.y = lerp(-800, gravity, lerp_amount)
    yield(get_tree(), "idle_frame")

    if is_on_floor():
        break
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 (97 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.