Add a first-view controller and a bunch of things
1. Replace 4k models with low-poly once 2. Use bare mixamo for testing 3. Add a basic menu 4. Add a map with collisions and spawn areas
This commit is contained in:
@ -4,12 +4,16 @@
|
||||
class_name Player extends CharacterBody3D
|
||||
|
||||
@export_category("Player")
|
||||
@export_range(1, 35, 1) var speed: float = 10 # m/s
|
||||
@export_range(10, 400, 1) var acceleration: float = 100 # m/s^2
|
||||
@export_range(1, 35, 1) var speed: float = 11 # m/s
|
||||
@export_range(10, 400, 1) var acceleration: float = 90 # m/s^2
|
||||
|
||||
@export_range(0.1, 3.0, 0.1) var jump_height: float = 1 # m
|
||||
@export_range(0.1, 3.0, 0.1, "or_greater") var camera_sens: float = 1
|
||||
|
||||
@onready var upper_torso: CSGSphere3D = $UpperTorso
|
||||
@onready var upper_torso_default_position: Vector3 = upper_torso.position
|
||||
@export var ANIMATION_PLAYER : AnimationPlayer
|
||||
@onready var body: Node3D = $RealBody
|
||||
var jumping: bool = false
|
||||
var mouse_captured: bool = false
|
||||
|
||||
@ -22,20 +26,23 @@ var walk_vel: Vector3 # Walking velocity
|
||||
var grav_vel: Vector3 # Gravity velocity
|
||||
var jump_vel: Vector3 # Jumping velocity
|
||||
|
||||
@onready var camera: Node3D = $Body/UpperTorso
|
||||
var is_crouch: bool = false
|
||||
|
||||
@onready var camera: Node3D = $UpperTorso
|
||||
@onready var character: Node3D = $"."
|
||||
|
||||
func _ready() -> void:
|
||||
capture_mouse()
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
look_dir = event.relative * 0.001
|
||||
if mouse_captured: _rotate_camera()
|
||||
if Input.is_action_just_pressed("jump"): jumping = true
|
||||
if Input.is_action_just_pressed("exit"): get_tree().quit()
|
||||
if Input.is_action_just_pressed("shot"): $Body/UpperTorso/Pistol.shot()
|
||||
if Input.is_action_just_pressed("reload"): $Body/UpperTorso/Pistol.reload()
|
||||
if Input.is_action_just_pressed("shot"): $UpperTorso/Pistol.shot()
|
||||
if Input.is_action_just_pressed("reload"): $UpperTorso/Pistol.reload()
|
||||
if Input.is_action_just_pressed("crouch"): crouch()
|
||||
if Input.is_action_just_released("crouch"): uncrouch()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@ -67,9 +74,30 @@ func _walk(delta: float) -> Vector3:
|
||||
move_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backwards")
|
||||
var _forward: Vector3 = camera.global_transform.basis * Vector3(move_dir.x, 0, move_dir.y)
|
||||
var walk_dir: Vector3 = Vector3(_forward.x, 0, _forward.z).normalized()
|
||||
walk_vel = walk_vel.move_toward(walk_dir * speed * move_dir.length(), acceleration * delta)
|
||||
#_crouch(delta)
|
||||
var cur_speed: float
|
||||
if is_crouch:
|
||||
cur_speed = speed / 3
|
||||
#upper_torso.position.y -= 10
|
||||
else:
|
||||
cur_speed = speed
|
||||
if Input.is_action_pressed("silent_walk"):
|
||||
walk_vel = walk_vel.move_toward(walk_dir * (cur_speed / 1.5) * move_dir.length(), (acceleration / 1.5) * delta)
|
||||
else:
|
||||
walk_vel = walk_vel.move_toward(walk_dir * cur_speed * move_dir.length(), acceleration * delta)
|
||||
var body := $character
|
||||
|
||||
return walk_vel
|
||||
|
||||
func crouch():
|
||||
ANIMATION_PLAYER.play("Crouch", -1, 7.0)
|
||||
is_crouch = true
|
||||
|
||||
func uncrouch():
|
||||
ANIMATION_PLAYER.play("Crouch", -1, -7.0)
|
||||
is_crouch = false
|
||||
|
||||
|
||||
func _gravity(delta: float) -> Vector3:
|
||||
grav_vel = Vector3.ZERO if is_on_floor() else grav_vel.move_toward(Vector3(0, velocity.y - gravity, 0), gravity * delta)
|
||||
return grav_vel
|
||||
|
Reference in New Issue
Block a user