добавлены модели анимации персонажа

This commit is contained in:
lapich committed 2026-10-20 04:05:05 +03:00
1 parent 11d57bec19
commit 202a894140
824 files changed
+985212 -40

No files matched your search

+23 -1
View File
@@ -16,13 +16,25 @@ public class PlayerMovement : MonoBehaviour
[Header("Камера")]
public Transform cam; // Ссылка на главную камеру
[Header("Анимация")]
public Animator animator; // Аниматор персонажа
private CharacterController controller;
private Vector3 velocity;
private float gravity = -9.81f;
private float currentAnimSpeed = 0f;
void Start()
{
controller = GetComponent<CharacterController>();
if (animator == null)
animator = GetComponentInChildren<Animator>();
if (animator != null)
{
animator.SetFloat("Speed", 0f);
animator.SetBool("IsMoving", false);
}
// Скрываем и блокируем курсор
Cursor.lockState = CursorLockMode.Locked;
@@ -62,8 +74,9 @@ public class PlayerMovement : MonoBehaviour
}
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
bool isMoving = direction.magnitude >= 0.1f;
if (direction.magnitude >= 0.1f)
if (isMoving)
{
// Вычисляем угол поворота с учетом направления камеры
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
@@ -77,6 +90,15 @@ public class PlayerMovement : MonoBehaviour
controller.Move(moveDir.normalized * currentSpeed * Time.deltaTime);
}
// Обновляем параметры аниматора
if (animator != null)
{
float targetSpeed = isMoving ? currentSpeed : 0f;
currentAnimSpeed = Mathf.MoveTowards(currentAnimSpeed, targetSpeed, 12f * Time.deltaTime);
animator.SetFloat("Speed", currentAnimSpeed);
animator.SetBool("IsMoving", isMoving);
}
// Применяем гравитацию
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);