This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
–1 vote

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 air
acceleration = 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():

func input(event):
if event is InputEventMouseMotion:
y(deg2rad(-event.relative.x * mousesensitivity))
x(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
    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"):

if Input.is_action_just_pressed("ui_accept"):

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)
Godot version v3.5
in Engine by (13 points)
retagged by

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.