0 votes

So, basically, I don't want the player to be able to change their direction mid-air. I attempted to do this by preserving their vector of motion. However, after many failed attempts, I'm stumped.

Right now, the player stops dead in their tracks and just jumps straight up.
extends KinematicBody

export var speed = 10.0
export var acceleration = 9.8
export var jumpPower = 50.0
export var sensitivity = 0.3
export var gravity = 30

var isJumping = false
var velocity = Vector3()
var camera_x_rotation = 0
onready var head_basis

func _ready():
    isJumping = false
    head_basis = head.get_global_transform().basis
#and more code
func _process(delta):
    if Input.is_action_just_pressed("ui_cancel"):

    if Input.is_action_just_pressed("fire"):

func  _physics_process(delta):

    if is_on_floor():
        isJumping = false
        head_basis = head.get_global_transform().basis

    var direction = Vector3()

    if not isJumping:
        if Input.is_action_pressed("move_forward"):
            direction -= head_basis.z
        elif Input.is_action_pressed("move_backward"):
            direction += head_basis.z

        if Input.is_action_pressed("move_left"):
            direction -= head_basis.x
        elif Input.is_action_pressed("move_right"):
            direction += head_basis.x

        if Input.is_action_just_pressed("move_jump"):
            isJumping = true
            velocity.y += jumpPower

    if not is_on_floor():
        velocity.y -= gravity* delta
    direction = direction.normalized()

    velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
    velocity = move_and_slide(velocity,Vector3.UP)
Godot version 3.2.3
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.