The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I want my FPC to move smoother but I don't know how to do it.

I will leave the code here:

extends KinematicBody

# Variables basicas
var velocity = Vector3()
var gravity = -30
var max_speed = 8
var mouse_sens = 0.002

# Variables para armas

# Funciones
func _ready():

func get_input():
    var input_dir = Vector3()

    # Movimiento
    if Input.is_action_pressed("move_forward"):
        input_dir += -global_transform.basis.z
    if Input.is_action_pressed("move_back"):
        input_dir += global_transform.basis.z
    if Input.is_action_pressed("strafe_left"):
        input_dir += -global_transform.basis.x
    if Input.is_action_pressed("strafe_right"):
        input_dir += global_transform.basis.x
    input_dir = input_dir.normalized()
    return input_dir

func _unhandled_input(event):
    if event is InputEventMouseMotion:
        rotate_y(-event.relative.x * mouse_sens)
        $Pivot.rotate_x(-event.relative.y * mouse_sens)
        $Pivot.rotation.x = clamp($Pivot.rotation.x, -1.2, 1.2)

func _physics_process(delta):
    # Gravedad
    velocity.y += gravity * delta
    var desired_velocity = get_input() * max_speed
    velocity.x = desired_velocity.x
    velocity.z = desired_velocity.z
    velocity = move_and_slide(velocity, Vector3.UP, true)

# warning-ignore:unused_argument
func change_gun(gun):

# warning-ignore:unused_argument
func _process(delta):
Godot version 3.5
in Engine by (51 points)

1 Answer

+1 vote
Best answer

I would suggest using a damping system because ist a bit more realistic and also easier to Work with. Something like this should do the Trick:

velocity.x += max_speed * get_input().x
velocity.z += max_speed * get_input().z

velocity.x *= pow(1.0 - damping, delta * 10)
velocity.z *= pow(1.0 - damping, delta * 10)

This ensures thats the acceleratoon from 0 to 100 ist bigger then from 100 to 200. Of course this method also has some downsights, for example you can't CLEANLY Control between acceleration and deceleration. This method is from
[Jonas Tyroller : 5 Reasons your Indie Platformer sucks] .
It has a lot of useful tips that I also use in my FPS Game. I can only recommend it.
I hope that I could help you. :)

by (56 points)
selected by

it worked, thx so much!
and also i going to look that video :)))

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.