wip: OctoPlayerDriver & New Triggers for OctoWorldEvent & Critical Path V1

This commit is contained in:
Alexandre Coirier
2026-05-19 23:40:16 +02:00
parent 578b94f1dc
commit 1cff87b60b
37 changed files with 6172 additions and 885 deletions
@@ -1,8 +1,7 @@
using OctoCore.Inputs;
using System.Linq;
using System.Globalization;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
namespace OctoCore.Components
{
@@ -21,13 +20,7 @@ namespace OctoCore.Components
public bool IsRunning;
public float Yaw;
public float Pitch;
[Space(10)]
public bool IsDriven;
[Range(0, 1)] public float DriventIntensity;
public Transform DriveTarget;
public Transform DriveLookAt;
public OctoPlayerDriver Driver;
}
[System.Serializable]
@@ -68,7 +61,7 @@ namespace OctoCore.Components
}
[System.Serializable]
private class FirstPerson
public class FirstPerson
{
[Header("References")]
@@ -110,6 +103,7 @@ namespace OctoCore.Components
public bool IsPaused => State.IsPaused;
public float Radius => _references.Controller ? _references.Controller.radius : 0;
public FirstPerson _FirstPerson => _firstPerson;
void OnEnable()
{
@@ -143,6 +137,17 @@ namespace OctoCore.Components
HandleMovement();
}
public void Teleport(string positionAndYaw)
{
string[] s = positionAndYaw.Replace(" ", string.Empty).Split(',');
float x = float.Parse(s[0], CultureInfo.InvariantCulture.NumberFormat);
float y = float.Parse(s[1], CultureInfo.InvariantCulture.NumberFormat);
float z = float.Parse(s[2], CultureInfo.InvariantCulture.NumberFormat);
float a = float.Parse(s[3], CultureInfo.InvariantCulture.NumberFormat);
Teleport(new Vector3(x, y, z), Quaternion.Euler(0, a, 0));
}
public void Teleport(Vector3 position, Quaternion rotation)
{
State.IsPaused = _jumpInput = _jumpping = _runInput = false;
@@ -169,20 +174,9 @@ namespace OctoCore.Components
if (OctoCore.Instance)
OctoCore.Instance.UI.SetCursor();
}
public void Drive(Transform target, Transform lookAt)
{
State.DriveTarget = target;
State.DriveLookAt = lookAt;
State.IsDriven = true;
}
public void ReleaseDrive()
{
State.IsDriven = false;
State.DriveTarget = null;
State.DriveLookAt = null;
}
public void Drive(OctoPlayerDriver driver) { State.Driver = driver; }
public void ReleaseDrive() { State.Driver = null; }
public void SetYaw(float yaw) { State.Yaw = yaw; }
public void SetPitch(float pitch) { State.Yaw = pitch; }
@@ -259,21 +253,8 @@ namespace OctoCore.Components
move = camRight * move.x + camForward * move.z;
}
if (State.IsDriven)
{
State.DriventIntensity = Mathf.Clamp01(State.DriventIntensity + move.magnitude * t * 1);
Vector3 driveDir = State.DriveTarget.position - transform.position;
float driveAtten = 1 - Mathf.Clamp01(driveDir.magnitude);
Vector3 driveMove = driveDir;
driveMove.y = 0;
driveMove = driveMove.normalized * move.magnitude;
driveMove = Vector3.Lerp(driveMove, Vector3.zero, driveAtten);
move = Vector3.Lerp(move, driveMove, State.DriventIntensity);
}
if (State.Driver)
State.Driver.ApplyMoveInfluence(move, move.magnitude * t, out move);
float deltaSmooth = t * (accelerating ? 30 : 15);
_moveDirection = Vector3.Lerp(_moveDirection, move, deltaSmooth * 1.5f);
@@ -349,25 +330,8 @@ namespace OctoCore.Components
State.Yaw += mouseX;
State.Pitch = Mathf.Clamp(State.Pitch + mouseY, _firstPerson.MinPitch, _firstPerson.MaxPitch);
if (State.IsDriven)
{
Vector3 lookAt = State.DriveLookAt.position - _firstPerson.Camera.transform.position;
lookAt = lookAt.normalized;
Vector3 playerPos2D = transform.position;
Vector3 targetPos2D = State.DriveTarget.position;
playerPos2D.y = targetPos2D.y = 0;
float yaw = Mathf.Atan2(lookAt.x, lookAt.z) * Mathf.Rad2Deg;
float pitch = Mathf.Asin(-lookAt.y) * Mathf.Rad2Deg;
float lerp = 1 - Mathf.Clamp01(Vector3.Distance(playerPos2D, targetPos2D) / 2);
float yawRange = Mathf.Lerp(180, 0, lerp);
float pitchRange = Mathf.Lerp(90, 0, lerp);
State.Yaw = yaw + Mathf.Clamp(Mathf.DeltaAngle(yaw, State.Yaw), -yawRange, yawRange);
State.Pitch = pitch + Mathf.Clamp(Mathf.DeltaAngle(pitch, State.Pitch), -pitchRange, pitchRange);
}
if (State.Driver)
State.Driver.ApplyLookInfluence(State.Yaw, State.Pitch, Time.deltaTime, out State.Yaw, out State.Pitch);
Quaternion YawRot = Quaternion.Euler(0, State.Yaw, 0);
Quaternion PitchRot = Quaternion.Euler(State.Pitch, 0, 0);