working on fpp character animations

This commit is contained in:
2025-06-22 10:45:09 +02:00
parent a899c1f4d6
commit c8cfb28a7b
43 changed files with 9763 additions and 2190 deletions

View File

@@ -0,0 +1,36 @@
using RebootKit.Engine.Services.Simulation;
using RebootReality.jelycho.Main;
using UnityEngine;
namespace RebootReality.jelycho.Abilities {
public class AbilitiesContainer : Actor {
public AbilitiesContainer() {
}
public void AddAbility(AbilityEffect ability) {
}
public void RemoveAbility(AbilityEffect ability) {
}
public override void OnTick(float deltaTime) {
}
}
public abstract class AbilityEffect {
public AbilityEffect() {
}
protected void EndAbility() {
}
public abstract void OnTick(Actor target, float deltaTime);
}
[CreateAssetMenu(menuName = GameConsts.k_CreateAssetMenu + "Ability Asset", fileName = "ability_empty")]
public class AbilityAsset : ScriptableObject {
}
}

View File

@@ -1,11 +0,0 @@
namespace RebootReality.jelycho.Abilities {
public interface IAbility {
}
public class AbilitySystem {
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79a619ce27ce4da4af49583207ffca01
timeCreated: 1750333120

View File

@@ -0,0 +1,9 @@
using RebootKit.Engine.Services.Simulation;
namespace RebootReality.jelycho.Beacons {
public class BeaconActor : Actor {
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f5b1ca118d5b4d689660039de71a6625
timeCreated: 1750333126

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 31bebe68be334bdfa40d990dca5367a7
timeCreated: 1750333198

View File

@@ -3,7 +3,7 @@ using RebootReality.jelycho.Main;
using UnityEngine;
using UnityEngine.AI;
namespace RebootReality.jelycho {
namespace RebootReality.jelycho.Enemies {
[AddComponentMenu(GameConsts.k_AddComponentMenu + "Zombie Actor")]
public class ZombieActor : Actor {
[SerializeField] NavMeshAgent m_NavMeshAgent;

View File

@@ -54,7 +54,7 @@ namespace RebootReality.jelycho.Player {
public void Tick() {
Camera.Lens.FieldOfView = s_cameraFOV.FloatValue;
Camera.transform.localRotation = Quaternion.Euler(Pitch, 0f, 0f);
// Camera.transform.localRotation = Quaternion.Euler(Pitch, 0f, 0f);
}
public void Rotate(float x, float y) {

View File

@@ -1,4 +1,5 @@
using RebootKit.Engine.Extensions;
using System;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Services.Simulation;
using Unity.Mathematics;
@@ -7,7 +8,7 @@ using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootReality.jelycho.Player {
public class PlayerActor : Actor {
static readonly Logger s_logger = new Logger(nameof(PlayerActor));
static readonly Logger s_Logger = new Logger(nameof(PlayerActor));
[SerializeField] Animator m_Animator;
@@ -17,7 +18,6 @@ namespace RebootReality.jelycho.Player {
[Header("Camera")]
[SerializeField] FPPCamera m_Camera;
[SerializeField] CameraSpring m_CameraSpring;
[SerializeField] Transform m_HeadBoneTransform;
[SerializeField, Range(0.0f, 1.0f), Tooltip("Percentage of run speed")]
float m_EnableCameraBobbingPercentThreshold = 0.5f;
@@ -29,23 +29,44 @@ namespace RebootReality.jelycho.Player {
float m_TargetCameraBobbing = 0.0f;
float m_CurrentCameraBobbing = 0.0f;
[Header("Character")]
[SerializeField] Transform m_CharacterRootTransform;
[SerializeField] Transform m_HeadBoneTransform;
[SerializeField] Transform m_HeadAimTargetTransform;
[SerializeField] Transform m_CharacterForwardTransform;
[SerializeField, Range(0.0f, 90.0f)] float m_CharacterRotateDeadAngle = 5.0f;
[SerializeField, Range(0.0f, 90.0f)] float m_CharacterRotateSoftAngle = 90.0f;
[SerializeField] float m_CharacterRotateSpeed = 180.0f;
[SerializeField] float m_CharacterRotateFastSpeed = 720.0f;
float m_CharacterTurnVelocity = 0.0f;
[Header("Dragging")]
[SerializeField] Transform m_DragGutStartPosition;
[SerializeField] PhysicsObjectDragger m_PhysicsDragger;
[SerializeField] FloatRange m_DragDistanceRange = new FloatRange(1.0f, 5.0f);
[SerializeField] LineRenderer m_LineRenderer;
public float3 LookDirection {
get {
float pitchRad = math.radians(-m_Camera.Pitch);
float yawRad = math.radians(m_Camera.Yaw);
return new float3(math.sin(yawRad) * math.cos(pitchRad),
math.sin(pitchRad),
math.cos(yawRad) * math.cos(pitchRad));
}
}
public override void OnBeginPlay() {
m_CameraSpring.Initialize();
}
public override void OnTick() {
public override void OnTick(float deltaTime) {
// Camera Stuff
m_Camera.Tick();
m_Locomotion.YawRotation = m_Camera.Yaw;
// Camera bobbing
if (m_Locomotion.IsGrounded &&
m_Locomotion.SpeedXZ >= m_Locomotion.runSpeed * m_EnableCameraBobbingPercentThreshold) {
if (m_Locomotion.IsSprinting) {
@@ -62,22 +83,50 @@ namespace RebootReality.jelycho.Player {
m_CameraBobbingTransitionSpeed * Time.deltaTime);
m_Camera.SetBobbing(m_CurrentCameraBobbing);
m_PhysicsDragger.TargetWorldPosition = m_Camera.Camera.transform.position +
m_Camera.Camera.transform.forward * 2.0f;
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));
} else {
m_LineRenderer.enabled = false;
}
Vector3 actorUp = transform.up;
Vector3 actorRight = transform.right;
Vector3 actorForward = transform.forward;
m_CameraSpring.UpdateSpring(Time.deltaTime, actorUp, actorRight, actorForward);
// Character rotation
float3 targetCharacterForward = math.normalize(LookDirection.With(y: 0.0f));
float3 currentCharacterForward = math.normalize(m_CharacterForwardTransform.forward.With(y: 0.0f));
float angleRad = math.acos(math.clamp(math.dot(targetCharacterForward, currentCharacterForward) / (math.length(targetCharacterForward) * math.length(currentCharacterForward)), -1f, 1f));
float angleDeg = math.degrees(angleRad);
bool rotateCharacter = false;
float rotateCharacterSpeed = m_CharacterRotateSpeed;
m_CharacterTurnVelocity = 0.0f;
if (math.abs(angleDeg) > m_CharacterRotateDeadAngle) {
if (math.abs(angleDeg) < m_CharacterRotateSoftAngle) {
rotateCharacter = true;
} else {
rotateCharacter = true;
rotateCharacterSpeed = m_CharacterRotateFastSpeed;
}
}
float velocityForward = m_Locomotion.Velocity.z;
if (!rotateCharacter && math.abs(velocityForward) > 0.01f) {
rotateCharacter = true;
}
if (rotateCharacter) {
m_CharacterTurnVelocity = rotateCharacterSpeed * deltaTime;
Vector3 newForward = Vector3.RotateTowards(currentCharacterForward,
targetCharacterForward,
math.radians(m_CharacterTurnVelocity),
0.0f);
m_CharacterForwardTransform.forward = newForward;
}
// Aim Target adjustment
m_HeadAimTargetTransform.position = (float3)m_HeadBoneTransform.position + LookDirection * 5.0f;
UpdateAnimator();
}
@@ -98,7 +147,7 @@ namespace RebootReality.jelycho.Player {
}
public void SetMoveInput(Vector2 input) {
float3 direction = Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) *
float3 direction = Quaternion.AngleAxis(m_Camera.Yaw, Vector3.up) *
new float3(input.x, 0.0f, input.y);
m_Locomotion.SetWishDirection(direction);
}
@@ -115,19 +164,29 @@ namespace RebootReality.jelycho.Player {
}
struct AnimatorParamHashes {
public static readonly int s_VelocityForwardNormalized = Animator.StringToHash("VelocityForwardNormalized");
public static readonly int s_VelocityRightNormalized = Animator.StringToHash("VelocityRightNormalized");
public static readonly int s_IsGrounded = Animator.StringToHash("IsGrounded");
public static readonly int VelocityForwardNormalized = Animator.StringToHash("VelocityForwardNormalized");
public static readonly int VelocityRightNormalized = Animator.StringToHash("VelocityRightNormalized");
public static readonly int TurnVelocity = Animator.StringToHash("TurnVelocity");
public static readonly int IsGrounded = Animator.StringToHash("IsGrounded");
}
void UpdateAnimator() {
Vector3 localVelocity = m_Locomotion.LocalVelocity;
Vector3 localVelocity = m_CharacterForwardTransform.InverseTransformDirection(m_Locomotion.Velocity);
float forwardNormalized = localVelocity.z / m_Locomotion.runSpeed;
float rightNormalized = localVelocity.x / m_Locomotion.runSpeed;
m_Animator.SetFloat(AnimatorParamHashes.s_VelocityForwardNormalized, forwardNormalized);
m_Animator.SetFloat(AnimatorParamHashes.s_VelocityRightNormalized, 0.0f);
float turnVelocity = m_CharacterTurnVelocity;
if (math.abs(forwardNormalized) > 0.01f ||
math.abs(rightNormalized) > 0.01f ||
!m_Locomotion.IsGrounded) {
turnVelocity = 0.0f;
}
m_Animator.SetFloat(AnimatorParamHashes.VelocityForwardNormalized, forwardNormalized);
m_Animator.SetFloat(AnimatorParamHashes.VelocityRightNormalized, rightNormalized);
m_Animator.SetFloat(AnimatorParamHashes.TurnVelocity, turnVelocity);
m_Animator.SetBool(AnimatorParamHashes.s_IsGrounded, m_Locomotion.IsGrounded);
m_Animator.SetBool(AnimatorParamHashes.IsGrounded, m_Locomotion.IsGrounded);
}
}
}

View File

@@ -12,7 +12,7 @@ using Object = UnityEngine.Object;
namespace RebootReality.jelycho.Player {
public class PlayerController : IController {
readonly Logger s_logger = new Logger(nameof(PlayerController));
readonly Logger m_Logger = new Logger(nameof(PlayerController));
readonly Config m_Config;
PlayerActor m_FPPActor;
@@ -29,7 +29,7 @@ namespace RebootReality.jelycho.Player {
RR.Input.EnableControls();
m_FPPActor = await RR.World.SpawnActor<PlayerActor>(m_Config.playerActorPrefab, cancellationToken);
m_FPPActor.Simulate = true;
m_FPPActor.IsPlaying = true;
if (RR.World.Context is WorldContext worldContext) {
m_FPPActor.WarpTo(worldContext.PlayerSpawnPoint.position);
@@ -41,14 +41,13 @@ namespace RebootReality.jelycho.Player {
public void OnStop() {
RR.Input.DisableControls();
RR.Input.UnlockCursor();
Object.Destroy(m_FPPActor);
RR.World.KillActor(m_FPPActor);
}
public void OnTick() {
if (m_FPPActor is null) {
s_logger.Error("Player actor is not initialized. Make sure to call OnStart() before OnTick().");
m_Logger.Error("Player actor is not initialized. Make sure to call OnStart() before OnTick().");
return;
}

View File

@@ -64,6 +64,13 @@ namespace RebootReality.jelycho.Player {
}
}
public Vector3 Velocity {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
return m_LastVelocity;
}
}
void Awake() {
m_Motor.CharacterController = this;
}