![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ash33 |
hello, i want to achieve forward jump by pressing one key i.e. w key.
func _process(delta):
var target_dir = Vector3(0,0,0)
if Input.is_action_pressed("forward") and is_on_floor():
target_dir.z += 1
target_dir.y = jum_force
if Input.is_action_pressed("left") and is_on_floor():
target_dir.x += 1
target_dir.y = jum_force
if Input.is_action_pressed("right") and is_on_floor():
target_dir.x -= 1
target_dir.y = jum_force
if Input.is_action_just_pressed("space") and is_on_floor():
vel.y = jum_force
target_dir = target_dir.normalized()
vel.x = lerp(vel.x , target_dir.x * speed, accel * delta )
vel.z = lerp(vel.z , target_dir.z * speed, accel * delta )
vel.y = lerp(vel.y , target_dir.y * speed, accel * delta )
vel.y += grav * delta
if vel.y < max_grav:
vel.y = max_grav
move_and_slide(vel, Vector3(0, 1, 0))
if is_on_floor() and vel.y < 0:
vel.y = 0
this is my code. on space it works fine but player jump on it current position and on click of w it go forward with small jumps
thanks in advance if u show interest and try to analyze my code