2025-07-27 23:48:47 +02:00
|
|
|
using System.Collections.Generic;
|
2025-06-23 16:30:18 +02:00
|
|
|
using UnityEngine;
|
2025-08-06 00:55:06 +02:00
|
|
|
using TMPro;
|
2025-06-23 16:30:18 +02:00
|
|
|
|
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float moveSpeed = 5f;
|
|
|
|
|
public float sprintSpeed = 10f;
|
|
|
|
|
public float gravity = -9.81f;
|
|
|
|
|
public float rotationSpeed = 10f;
|
|
|
|
|
|
2025-08-28 17:09:35 +02:00
|
|
|
public float dashSpeed;
|
|
|
|
|
public float dashDuration;
|
|
|
|
|
|
2025-06-23 16:30:18 +02:00
|
|
|
private CharacterController controller;
|
|
|
|
|
private Vector3 velocity;
|
2025-08-28 01:40:22 +02:00
|
|
|
private Vector3 move;
|
2025-07-27 23:48:47 +02:00
|
|
|
private PlayerSkillTree PlayerSkills;
|
2025-08-28 01:40:22 +02:00
|
|
|
private PlayerSkillHandler playerSkillHandler;
|
2025-07-27 23:48:47 +02:00
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
PlayerSkills = PlayerSkillTree.Instance;
|
2025-08-28 17:58:02 +02:00
|
|
|
playerSkillHandler = GetComponent<PlayerSkillHandler>();
|
2025-07-27 23:48:47 +02:00
|
|
|
}
|
2025-06-23 16:30:18 +02:00
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
controller = GetComponent<CharacterController>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-27 23:48:47 +02:00
|
|
|
private void Update()
|
|
|
|
|
{
|
2025-08-31 00:25:23 +02:00
|
|
|
|
2025-07-27 23:48:47 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-23 16:30:18 +02:00
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
HandleMovement();
|
|
|
|
|
ApplyGravity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleMovement()
|
|
|
|
|
{
|
|
|
|
|
float moveX = Input.GetAxisRaw("Horizontal");
|
|
|
|
|
float moveZ = Input.GetAxisRaw("Vertical");
|
2025-08-28 01:40:22 +02:00
|
|
|
move = new Vector3(moveX, 0, moveZ).normalized;
|
2025-06-23 16:30:18 +02:00
|
|
|
|
|
|
|
|
if (move.magnitude >= 0.1f)
|
|
|
|
|
{
|
|
|
|
|
float currentSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : moveSpeed;
|
|
|
|
|
|
|
|
|
|
Quaternion targetRotation = Quaternion.LookRotation(move);
|
|
|
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime);
|
|
|
|
|
|
|
|
|
|
controller.Move(move * currentSpeed * Time.fixedDeltaTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ApplyGravity()
|
|
|
|
|
{
|
|
|
|
|
if (IsGrounded() && velocity.y < 0) velocity.y = -2f;
|
|
|
|
|
velocity.y += gravity * Time.fixedDeltaTime;
|
|
|
|
|
controller.Move(velocity * Time.fixedDeltaTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsGrounded()
|
|
|
|
|
{
|
|
|
|
|
float groundDistance = 0.2f;
|
|
|
|
|
return Physics.Raycast(transform.position, Vector3.down, groundDistance);
|
|
|
|
|
}
|
2025-07-27 23:48:47 +02:00
|
|
|
|
|
|
|
|
public List<PlayerSkillTree.Skills> GetPlayerSkills()
|
|
|
|
|
{
|
|
|
|
|
return PlayerSkills.GetPlayerSkills();
|
|
|
|
|
}
|
2025-06-23 16:30:18 +02:00
|
|
|
}
|