Minimum move amount in 3D FPS?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hermo


I’m using this popular open source 3d (first person shooter) character controller for Godot.

It works perfectly, but I want to implement a minimum move amount, meaning:

Right now, if the player presses and releases a move key (up, down…) really quickly the player moves by a really tiny amount (as expected).

How can I make that if the amount (of pixels I guess) is less than some variable (e.g., min_move = 10), the player still moves to make the minimum amount?

Thank you very much!

extends CharacterBody3D
class_name MovementController

@export var gravity_multiplier := 3.0
@export var speed := 10
@export var acceleration := 8
@export var deceleration := 10
@export_range(0.0, 1.0, 0.05) var air_control := 0.3
@export var jump_height := 10
var direction := Vector3()
var input_axis := Vector2()
# Get the gravity from the project settings to be synced with RigidDynamicBody nodes.
@onready var gravity: float = (ProjectSettings.get_setting("physics/3d/default_gravity") 
		* gravity_multiplier)

# Called every physics tick. 'delta' is constant
func _physics_process(delta: float) -> void:
	input_axis = Input.get_vector(&"move_back", &"move_forward",
			&"move_left", &"move_right")
	if is_on_floor():
		if Input.is_action_just_pressed(&"jump"):
			velocity.y = jump_height
		velocity.y -= gravity * delta

func direction_input() -> void:
	direction = Vector3()
	var aim: Basis = get_global_transform().basis
	direction = aim.z * -input_axis.x + aim.x * input_axis.y

func accelerate(delta: float) -> void:
	# Using only the horizontal velocity, interpolate towards the input.
	var temp_vel := velocity
	temp_vel.y = 0
	var temp_accel: float
	var target: Vector3 = direction * speed
	if > 0:
		temp_accel = acceleration
		temp_accel = deceleration
	if not is_on_floor():
		temp_accel *= air_control
	temp_vel = temp_vel.lerp(target, temp_accel * delta)
	velocity.x = temp_vel.x
	velocity.z = temp_vel.z