player character has move and dodge
This commit is contained in:
@@ -1,34 +1,23 @@
|
||||
extends CharacterBody3D
|
||||
class_name Player
|
||||
|
||||
var input_dir
|
||||
var dodge_direction
|
||||
|
||||
@onready var body: MeshInstance3D = $Body
|
||||
@onready var anim_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
const MAX_STAMINA : float = 100
|
||||
var stamina = MAX_STAMINA
|
||||
const STAMINA_REGEN_RATE = 10.0
|
||||
|
||||
const MOVE_SPEED = 10.0
|
||||
const MOVE_TRANSITION_SPEED = 7.0
|
||||
## Gameplay Settings
|
||||
const DODGE_STAMINA_COST = 30.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
standard_movement(delta)
|
||||
|
||||
body_look_at_mouse()
|
||||
apply_gravity(delta)
|
||||
stamina_regen(delta)
|
||||
move_and_slide()
|
||||
|
||||
func body_look_at_mouse():
|
||||
var mouse_raycast = MousePos.get_mouse_world_position()
|
||||
if mouse_raycast != null:
|
||||
body.look_at(Vector3(mouse_raycast.x,body.global_position.y,mouse_raycast.y),Vector3.UP)
|
||||
|
||||
func apply_gravity(delta):
|
||||
if !is_on_floor():
|
||||
velocity.y -= 9.8 * delta
|
||||
|
||||
func standard_movement(delta):
|
||||
input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
|
||||
if input_dir != null:
|
||||
velocity.x = lerp(velocity.x, input_dir.x * MOVE_SPEED,delta * MOVE_TRANSITION_SPEED)
|
||||
velocity.z = lerp(velocity.z, input_dir.y * MOVE_SPEED,delta * MOVE_TRANSITION_SPEED)
|
||||
func stamina_regen(delta):
|
||||
if stamina < MAX_STAMINA:
|
||||
print("STAMINA : ", stamina)
|
||||
stamina = clamp(stamina + delta * STAMINA_REGEN_RATE,0,MAX_STAMINA)
|
||||
|
||||
Reference in New Issue
Block a user