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
#blah-blah
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
isJumping = false
head_basis = head.get_global_transform().basis
#code
#code
#code
#and more code
func _process(delta):
if Input.is_action_just_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed("fire"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
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)