||Topic was automatically imported from the old Question2Answer platform.
Hello. I am looking to make a jump kind of like the game Hollow Knight where jump height is determined by how long you hold the jump key down. I’ve looked at a few resources and also tested stuff by myself. I have something working but it’s not looking the way I want it to. Something about the way the player falls down after doing a short jump is just weird. It looks great if you do a full jump though. I am fairly new to the engine so if you have a solution, just explain it in baby terms. Thanks!
Here are the variables
var vel = Vector2()
var FLOOR = Vector2.UP
var jump_force = 600
var gravity = 80
vel.y += gravity
vel = move_and_slide(vel, FLOOR)
vel.y = -jump_force
if vel.y < -100:
vel.y = -100
Your code is well thought out for what you are trying to do but the result will look choppy because you are directly changing the value of the speed. Usually you want to avoid that by changin the accelaration, for smoother movement.
If for some reason you can’t do that then you must change the speed gradually and not just set it to an arbirtary value because it will look very unnatural.
In godot the tool we use to change any property gradually over a certain period in time is the node Tween.
Step 1) add a child node Tween
Step 2) change the stop_jump function to something like this
if vel.y < -100:
get_node("Tween").interpolate_property(self,'vel:y',vel.y, -100, 0.35,Tween.TRANS_SINE,Tween.EASE_OUT)
get_node(“Tween”).interpolate_property( self, #where the property you want to manipulate is
‘vel:y’, #the name of the property
vel.y, #the initial value
-100, #the value you will end on
0.35, # how much time it will take
Tween.TRANS_SINE,Tween.EASE_OUT) # changes the way the the property is animated
to learn more you can see these: