Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | tyreman |
extends CharacterBody3D
@export var SPEED = 5
@export var AIR_SPEED = 5
@export var SPRINT_SPEED = 5
@export var SPRINT_ACCEL = 0
@export var ACCEL_TIME = 0
@export var AIR_ACCEL_TIME = 0
@export var DEACCEL_TIME = 0
@export var AIR_DEACCEL_TIME = 0
@export var MOUSE_SENSITIVITY = 3
@export var SPRINT = false
@export var GRAVITY = 25
@export var JUMP_VELOCITY = 10
func _physics_process(delta):
# Add the GRAVITY.
velocity.y -= GRAVITY * delta
# Handle Jump.
if Input.is_action_pressed("ui_space") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Handle SPRINT.
if Input.is_action_pressed("ui_sprint"):
SPRINT = true
else:
SPRINT = false
# Get the input direction and handle the movement/deceleration.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
if is_on_floor():
if SPRINT: #SPRINTING
velocity.x = move_toward(velocity.x, direction.x * SPRINT_SPEED, SPRINT_ACCEL)
velocity.z = move_toward(velocity.z, direction.z * SPRINT_SPEED, SPRINT_ACCEL)
else: #WALKING
velocity.x = move_toward(velocity.x, direction.x * SPEED, ACCEL_TIME)
velocity.z = move_toward(velocity.z, direction.z * SPEED, ACCEL_TIME)
if direction:
if not is_on_floor(): #MOVING IN AIR
velocity.x = move_toward(velocity.x, direction.x * AIR_SPEED, AIR_ACCEL_TIME)
velocity.z = move_toward(velocity.z, direction.z * AIR_SPEED, AIR_ACCEL_TIME)
else: #GROUND FRICTION
velocity.x = move_toward(velocity.x, 0, DEACCEL_TIME)
velocity.z = move_toward(velocity.z, 0, DEACCEL_TIME)
if not is_on_floor(): #AIR RESISTANCE
velocity.x = move_toward(velocity.x, 0, AIR_DEACCEL_TIME)
velocity.z = move_toward(velocity.z, 0, AIR_DEACCEL_TIME)
move_and_slide()
Use beta 7 if this started when you started using beta 8.
magicalogic | 2022-12-13 14:04
it just stopped working mid project I spent like an hour making sure I didn’t miss anything but the console was empty.
tyreman | 2022-12-13 15:44
I’ve formatted your posted code for the forum to make it easier to read. Please try to do that in future posts (using the { }
button in the forums editor toolbar).
jgodfrey | 2022-12-13 20:41