working on fpp locomotion, camera spring

This commit is contained in:
2025-06-07 10:39:06 +02:00
parent 0abddece7e
commit e99314d5d8
40 changed files with 4112 additions and 462 deletions

View File

@@ -1,7 +1,6 @@
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;
@@ -9,22 +8,33 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RealityReboot.jelycho.Player {
public class PlayerActor : Actor {
static readonly Logger s_logger = new(nameof(PlayerActor));
[SerializeField] PlayerFPPLocomotion m_Locomotion;
[SerializeField] FPPCamera m_Camera;
[SerializeField] Animator m_Animator;
[SerializeField] Transform m_DragGutStartPosition;
[SerializeField] Animator m_Animator;
[Header("Movement")]
[SerializeField] PlayerFPPLocomotion m_Locomotion;
[Header("Camera")]
[SerializeField] FPPCamera m_Camera;
[SerializeField] CameraSpring m_CameraSpring;
[Header("Dragging")]
[SerializeField] Transform m_DragGutStartPosition;
[SerializeField] PhysicsObjectDragger m_PhysicsDragger;
[SerializeField] FloatRange m_DragDistanceRange = new(1.0f, 5.0f);
[SerializeField] LineRenderer m_LineRenderer;
public override void OnBeginPlay() {
m_CameraSpring.Initialize();
}
public override void OnTick() {
m_Locomotion.YawRotation = m_Camera.Yaw;
m_Camera.Tick();
m_PhysicsDragger.TargetWorldPosition = m_Camera.Camera.transform.position + m_Camera.Camera.transform.forward * 2.0f;
if (m_PhysicsDragger.Current.OrNull() != null) {
if (m_PhysicsDragger.Current.OrNull() is not null) {
m_LineRenderer.enabled = true;
m_LineRenderer.SetPosition(0, m_LineRenderer.transform.InverseTransformPoint(m_DragGutStartPosition.position));
m_LineRenderer.SetPosition(1, m_LineRenderer.transform.InverseTransformPoint(m_PhysicsDragger.Current.position));
@@ -32,8 +42,17 @@ namespace RealityReboot.jelycho.Player {
m_LineRenderer.enabled = false;
}
Vector3 actorUp = transform.up;
Vector3 actorRight = transform.right;
Vector3 actorForward = transform.forward;
m_CameraSpring.UpdateSpring(Time.deltaTime, actorUp, actorRight, actorForward);
UpdateAnimator();
}
public void SetSprint(bool isSprinting) {
m_Locomotion.SetSprint(isSprinting);
}
public void Jump() {
m_Locomotion.Jump();
@@ -44,7 +63,8 @@ namespace RealityReboot.jelycho.Player {
}
public void SetMoveInput(Vector2 input) {
float3 direction = Quaternion.AngleAxis(m_Camera.Yaw, Vector3.up) * new float3(input.x, 0.0f, input.y);
float3 direction = Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) *
new float3(input.x, 0.0f, input.y);
m_Locomotion.SetWishDirection(direction);
}
@@ -66,12 +86,12 @@ namespace RealityReboot.jelycho.Player {
}
void UpdateAnimator() {
float forwardNormalized = m_Locomotion.LocalVelocity.z / m_Locomotion.runSpeed;
m_Animator.SetFloat(AnimatorParamHashes.s_VelocityForwardNormalized, forwardNormalized);
m_Animator.SetFloat(AnimatorParamHashes.s_VelocityRightNormalized, 0.0f);
m_Animator.SetBool(AnimatorParamHashes.s_IsGrounded, m_Locomotion.IsGrounded);
// float forwardNormalized = m_Locomotion.LocalVelocity.z / m_Locomotion.runSpeed;
//
// m_Animator.SetFloat(AnimatorParamHashes.s_VelocityForwardNormalized, forwardNormalized);
// m_Animator.SetFloat(AnimatorParamHashes.s_VelocityRightNormalized, 0.0f);
//
// m_Animator.SetBool(AnimatorParamHashes.s_IsGrounded, m_Locomotion.IsGrounded);
}
}
}