Сделал базовое управление машиной и персонажем
This commit is contained in:
1 parent
10d42b72b8
commit
48753f65fb
152 files changed
+15117
-174
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
[Header("Movement Settings")]
|
||||
[SerializeField] private float moveSpeed = 4f;
|
||||
[SerializeField] private float gravity = -9.81f;
|
||||
|
||||
[Header("Ground Check")]
|
||||
[SerializeField] private Transform groundCheck;
|
||||
[SerializeField] private float groundDistance = 0.4f;
|
||||
[SerializeField] private LayerMask groundMask;
|
||||
|
||||
private CharacterController controller;
|
||||
private Vector3 velocity;
|
||||
private bool isGrounded;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
public void ProcessMove(Vector2 input)
|
||||
{
|
||||
// Проверка касания земли (сфера на уровне ног)
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if (isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f; // Небольшое прижатие к земле для стабильного спуска по склонам
|
||||
}
|
||||
|
||||
// Движение относительно локальных координат игрока
|
||||
Vector3 move = transform.right * input.x + transform.forward * input.y;
|
||||
controller.Move(move * (moveSpeed * Time.deltaTime));
|
||||
|
||||
// Применение гравитации
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user