The point of
KinematicBody is that it doesn’t have a velocity of is own, instead it’s up to you to decide what it should be. https://docs.godotengine.org/en/stable/classes/class_kinematicbody.html
Which means velocity is whatever you want. You can animate it, have your own variable storing it, add acceleration values to it over time in
_physics_process, reset it, or clamp it when collisions occur etc.
And then, the point is you should use that velocity when using
move_and_collide. If your character already moves, then you have such velocity in some way (otherwise I have no idea how you make it move^^).
Note that if you use
move_and_slide, it returns the velocity after sliding detection, which you may use to replace the previous velocity: https://docs.godotengine.org/en/stable/classes/class_kinematicbody.html#class-kinematicbody-method-move-and-slide
About jumping: in your case, when your character jumps, you could change the velocity depending on the velocity from last frame, something like this:
# Call once when the jump button is pressed
# Calculate a 0..1 factor based on known speeds the character can achieve on floor
var t = inverse_lerp(min_floor_speed, max_floor_speed, velocity.length())
# Add single jump velocity so the character will shoot upward
velocity = velocity + Vector2(0, lerp(t, min_jump_speed, max_jump_speed))
You don’t have to do it this way, it’s just an example of how to make jump speed depend on floor speed.
You can follow this tutorial for
KinematicBody2D: Using CharacterBody2D/3D — Godot Engine (stable) documentation in English
I know you use 3D, however the concepts are similar, it could help you understand the idea.
Kidscancode also made a video with
KinematicBody as part of his 3D series, which includes jumping: https://www.youtube.com/watch?v=ickZ_Genr7A
I did end up taking the velocity I was assigning to it and making that a single variable then using that for my air speed formula. Didn’t even cross my mind that I had assigned it’s velocity myself and so I already know it, which is why I’m going to sleep.
Thanks for all the other info and resources, helped me understand what I’m doing better (I was sort of just plugging code getting results and not fully understanding what it did to get said results).
Kair0ss | 2020-03-05 19:47