36 lines
863 B
GDScript3
Raw Normal View History

2024-01-16 22:01:16 +00:00
class_name Player
extends CharacterBody3D
2024-01-14 11:22:14 +00:00
2024-01-16 22:01:16 +00:00
const MOVE_SPEED = 4.5
const JUMP_VELOCITY = 4.5
const DECELERATE = 0.75
2024-01-14 11:22:14 +00:00
2024-01-16 22:01:16 +00:00
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var move: Vector2
func _input(_event):
move = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
func _physics_process(delta):
movement()
fall(delta)
move_and_slide()
func movement():
var direction = (Global.camera.transform.basis * Vector3(move.x, 0, move.y)).normalized()
# var direction = Vector3(move.x, 0, move.y).normalized()
if direction:
velocity.x = direction.x * MOVE_SPEED
velocity.z = direction.z * MOVE_SPEED
else:
velocity.x *= DECELERATE
velocity.z *= DECELERATE
func fall(delta):
if is_on_floor():
if Input.is_action_just_pressed("jump"):
velocity.y = JUMP_VELOCITY
else:
velocity.y -= gravity * delta