Files
jelito/Assets/jelycho/game/PlayerActor.cs
2025-04-14 23:22:05 +02:00

65 lines
2.2 KiB
C#

using System;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Services.Simulation;
using RebootKit.FPPKit;
using Unity.Mathematics;
using UnityEngine;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RealityReboot.jelycho.game {
public class PlayerActor : Actor {
static readonly Logger s_logger = new(nameof(PlayerActor));
[SerializeField] FPPLocomotion m_Locomotion;
[SerializeField] FPPCamera m_Camera;
[SerializeField] Transform m_DragGutStartPosition;
[SerializeField] PhysicsObjectDragger m_PhysicsDragger;
[SerializeField] FloatRange m_DragDistanceRange = new(1.0f, 5.0f);
[SerializeField] LineRenderer m_LineRenderer;
public override void OnTick() {
m_PhysicsDragger.TargetWorldPosition = m_Camera.Camera.transform.position + m_Camera.Camera.transform.forward * 2.0f;
if (m_PhysicsDragger.Current.OrNull() != null) {
m_LineRenderer.enabled = true;
m_LineRenderer.SetPosition(0, m_DragGutStartPosition.position);
m_LineRenderer.SetPosition(1, m_PhysicsDragger.Current.position);
} else {
m_LineRenderer.enabled = false;
}
}
public void Jump() {
m_Locomotion.Jump();
}
public void Look(Vector2 input) {
m_Camera.Rotate(input.x, input.y);
}
public void MoveRight(float input) {
float3 direction = Quaternion.AngleAxis(m_Camera.Yaw, Vector3.up) * Vector3.right;
m_Locomotion.AddMovementInput(direction, input);
}
public void MoveForward(float input) {
float3 direction = Quaternion.AngleAxis(m_Camera.Yaw, Vector3.up) * Vector3.forward;
m_Locomotion.AddMovementInput(direction, input);
}
public void StartDrag() {
GameObject pickedGameObject = m_Camera.Sensor.Sense();
if (pickedGameObject != null && pickedGameObject.TryGetComponent(out Rigidbody rigidbody)) {
m_PhysicsDragger.Grab(rigidbody);
}
}
public void StopDrag() {
m_PhysicsDragger.Drop();
}
}
}