feat: Player Move & Jump

This commit is contained in:
2026-05-27 12:00:10 +02:00
parent 16364e459c
commit ddeafd8901
3 changed files with 429 additions and 371 deletions

View File

@@ -1,8 +1,6 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
using static UnityEngine.CullingGroup;
public class Player : MonoBehaviour
{
@@ -260,17 +258,42 @@ public class Player : MonoBehaviour
private void SetVelocity(float deltaTime)
{
Vector2 input = _moveAction.ReadValue<Vector2>();
float speed = _settings.Speed * KMH_TO_MS;
Vector3 moveInput = new Vector3(input.x, 0, input.y); // Convert input 2D to move 3D
moveInput = Quaternion.Euler(0, _camera.transform.eulerAngles.y, 0) * moveInput; // Rotate move toward camera
moveInput *= speed; // Muliply move by speed
_state.Velocity.x = moveInput.x;
_state.Velocity.z = moveInput.z;
// Rotate Player
if (moveInput.sqrMagnitude > .001f)
{
Quaternion targetRot = Quaternion.LookRotation(moveInput);
float t = _settings.RotationSpeed * deltaTime;
Vector3 euler = Quaternion.Slerp(transform.rotation, targetRot, t).eulerAngles;
transform.rotation = Quaternion.Euler(0, euler.y, 0);
}
}
private void SetJump()
{
if (_jumpAction.triggered && _state.IsGrounded)
{
_state.Velocity.y = _settings.JumpForce;
_state.Ground = null;
}
}
private void SetMovement(float deltaTime)
{
Vector3 motion = _state.Velocity + _platformVelocity;
_references.Controller.Move(motion * deltaTime);
}
private void SetState()

View File

@@ -29,7 +29,7 @@ public class Rocket : MonoBehaviour
[SerializeField] private References _references;
[SerializeField] private Settings _settings;
[SerializeField] private State _state;
[SerializeField, ReadOnly] private State _state;
void OnEnable()
{