|
|
|
 |
Reply From: |
rustyStriker |
You can use the desmos site app and some basic movement functions:
V = V0 + at
y = v0*t + 0.5a*t²
when V
(velocity upwards) reaches 0 it means the body is at the peak of the jump, and using the second equation you can find the height it will jump.
just in case: y
and v
will be the Y axis and t
will be the X axis, V0
and a
are constants,V0
is the starting velocity(aka jump_force
) and a
is the acceleration(aka gravity
)
yea I think you explained ok but I dont know how to use that.
do I like. Put it i my code?
Anastasia | 2020-01-06 14:15
Assuming you code(jump part) is basically around a line like this:
velocity.y = -jump_force
then you can use a graph visualizer(desmos) in order to see the result of the jump(as for height and time in the air)
EDIT:
you only need the second graph, made a desmos link
Jump_force_calc | Desmos
v
is the initial jump(the -550 in your code)
a
is the gravity(needs to be less than 0)
do note that godot’s y axis goes down for positive and desmos’s y axis goes up for positive
rustyStriker | 2020-01-06 17:51
Indeed that is usefull. But being a newb i cant use it that well yet.
What i want to do, as stated above, is:
“when hes jumping hes going up with a constant speed. It would be much better if he started fast and the slowed down ONLY when he reaches max altitude!”
If you could help me with this I would be very thankfull!
Thank you for your help until now!
Edit:
My gravity is 7 and because the negative numbers go up it cant be less then 0
I’ll just show you
extends KinematicBody2D
const UP = Vector2(0, -100)
const ACCELERATION = 500
const MAX_SPEED = 800
var motion = Vector2()
var GRAVITY= 20
func _physics_process(delta):
var FRICTION = false
if Input. is_action_pressed("ui_right"):
motion.x = min(motion.x + ACCELERATION, MAX_SPEED)
$player.flip_h = false
$player.play("default")
elif Input. is_action_pressed("ui_left"):
motion.x = max(motion.x - ACCELERATION, -MAX_SPEED)
$player.flip_h = true
$player.play("default")
else:
motion.x = lerp(motion.x, 0, 0.1)
FRICTION = false
$player.play("default")
motion.y += 7
if is_on_floor():
if Input. is_action_just_pressed("ui_up"):
motion.y = -450
else:
if motion.y < 0:
$player.play("jump")
else:
$player.play("fall")
motion.y += GRAVITY
move_and_slide(motion, UP)
pass
Anastasia | 2020-01-06 18:07
Trying to understand what you want to do, sounds like you want to have a constant speed going upwards and when he reaches max altitude he will stop and fall.
that sounds really clanky if i got it right
rustyStriker | 2020-01-06 18:38