Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PugMasterPug | |
Old Version | Published before Godot 3 was released. |
I have a KinematicBody2D, to move it I use the function move_and_slide(speed)
, where speed
is a Vector2
, and it has simple gravity:
var spd = 500
var acceleration = 10
var jmpSpd = 800
var GRAVITY = 1300
var speed = Vector2()
func _ready():
set_process(true)
func _process(delta):
if Input.is_action_pressed("btn_jump") and is_on_floor():
speed.y = -jmpSpd
var desiredSpeed = 0
if Input.is_action_pressed("btn_right"):
desiredSpeed = spd
elif Input.is_action_pressed("btn_left"):
desiredSpeed = -spd
speed.x += (desiredSpeed - speed.x)*acceleration*delta
speed.y += GRAVITY*delta
speed = move_and_slide(speed)
The problem is that sometimes the player jumps higher than it should, and falls faster, and moves faster, this generally only happens when I have just turned on my computer, which makes me think that it has something to do with the number of times _process(delta)
is called, but I have no idea.
Maybe I should use move_and_slide(speed*delta)
, but then I would need very big values for all the variables, and when using move_and_slide(speed)
I get results much more similar to Godot 2 (this tutorial).
What should I do?
Thanks in advance