0 votes

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

Godot version V3.3.2
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.