using UnityEngine; using UnityEngine.InputSystem; // Dodaliśmy to! public class PlayerMove : MonoBehaviour { [Header("Ustawienia ruchu")] public float speed = 5f; [Header("Grawitacja")] public float gravity = -9.81f; // Wartość grawitacji private CharacterController controller; private Vector3 velocity; // Przechowuje prędkość w osi Y (spadanie) void Start() => controller = GetComponent(); void Update() { // --- 1. SPRAWDZANIE PODŁOŻA --- // isGrounded to wbudowana funkcja, która sprawdza czy dolna część Capsule Collidera dotyka ziemi if (controller.isGrounded && velocity.y < 0) { // Lekko dociskamy postać do ziemi, żeby nie ślizgała się na schodach/zboczach velocity.y = -2f; } // --- 2. NOWY SPOSÓB POBIERANIA WASD --- Vector2 moveInput = Vector2.zero; if (Keyboard.current != null) { if (Keyboard.current.wKey.isPressed) moveInput.y = 1; if (Keyboard.current.sKey.isPressed) moveInput.y = -1; if (Keyboard.current.aKey.isPressed) moveInput.x = -1; if (Keyboard.current.dKey.isPressed) moveInput.x = 1; } // --- 3. RUCH W POZIOMIE (Chodzenie) --- Vector3 move = transform.right * moveInput.x + transform.forward * moveInput.y; controller.Move(move * speed * Time.deltaTime); // --- 4. RUCH W PIONIE (Spadanie) --- // Aplikujemy przyspieszenie grawitacyjne do naszej prędkości spadania velocity.y += gravity * Time.deltaTime; // Poruszamy postacią w dół controller.Move(velocity * Time.deltaTime); } }