41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using Northbound;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
[Header("Movement Settings")]
|
|
[SerializeField] private float moveSpeed = 5f;
|
|
|
|
private Rigidbody rb;
|
|
private Vector3 moveDirection;
|
|
private PlayerInteraction playerInteraction;
|
|
|
|
void Start()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
rb.constraints = RigidbodyConstraints.FreezeRotation;
|
|
playerInteraction = GetComponent<PlayerInteraction>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (playerInteraction != null && playerInteraction.IsInteracting)
|
|
return;
|
|
|
|
float horizontal = Input.GetAxisRaw("Horizontal");
|
|
float vertical = Input.GetAxisRaw("Vertical");
|
|
|
|
moveDirection = new Vector3(horizontal, 0f, vertical).normalized;
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
rb.linearVelocity = new Vector3(
|
|
moveDirection.x * moveSpeed,
|
|
rb.linearVelocity.y,
|
|
moveDirection.z * moveSpeed
|
|
);
|
|
}
|
|
}
|