hello, I'm trying to do an fps and I'd like to know how to put air control in my game
can you help me ?
extends KinematicBody
var speed = 7
var acceleration = 20
var jump = 10
var gravity = 12
var hacceleration = 6
var airacceleration = 1
var normal_acceleration = 6
var gravity_vec = Vector3()
var mouse_sensitivity = 0.1
var direction = Vector3()
var velocity = Vector3()
var fall = Vector3()
var movement = Vector3()
var h_velocity = Vector3()
onready var head = $head
func ready():
Input.setmousemode(Input.MOUSEMODE_CAPTURED)
pass
func input(event):
if event is InputEventMouseMotion:
rotatey(deg2rad(-event.relative.x * mousesensitivity))
head.rotatex(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))
func physicsprocess(delta):
direction = Vector3()
if not is_on_floor():
gravity_vec += Vector3.DOWN * gravity * delta
h_acceleration = air_acceleration
elif is_on_floor():
gravity_vec = -get_floor_normal() * gravity
h_acceleration = normal_acceleration
else:
gravity_vec = -get_floor_normal()
h_acceleration = normal_acceleration
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
gravity_vec = Vector3.UP * jump
if Input.is_action_just_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed("ui_accept"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if Input.is_action_pressed("ui_up"):
direction -= transform.basis.z
elif Input.is_action_pressed("ui_down"):
direction += transform.basis.z
if Input.is_action_pressed("ui_left"):
direction -= transform.basis.x
elif Input.is_action_pressed("ui_right"):
direction += transform.basis.x
direction = direction.normalized()
velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
velocity = move_and_slide(velocity, Vector3.UP)
h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
movement.z = h_velocity.z + gravity_vec.z
movement.x = h_velocity.x + gravity_vec.x
movement.y = gravity_vec.y
move_and_slide(movement, Vector3.UP)