working on animations
This commit is contained in:
@@ -10,6 +10,7 @@ using RebootReality.jelycho.Items;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho.Player {
|
||||
@@ -134,6 +135,7 @@ namespace RebootReality.jelycho.Player {
|
||||
Inventory.OnItemDropped += OnItemDropped;
|
||||
|
||||
m_PlayerAnimator.onQuickAttackFinished.AddListener(OnQuickAttackFinishedAnimation);
|
||||
m_PlayerAnimator.onChargeReady.AddListener(OnChargeReadyAnimation);
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
@@ -141,6 +143,7 @@ namespace RebootReality.jelycho.Player {
|
||||
Inventory.OnItemDropped -= OnItemDropped;
|
||||
|
||||
m_PlayerAnimator.onQuickAttackFinished.RemoveListener(OnQuickAttackFinishedAnimation);
|
||||
m_PlayerAnimator.onChargeReady.RemoveListener(OnChargeReadyAnimation);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -271,7 +274,11 @@ namespace RebootReality.jelycho.Player {
|
||||
itemConfig.chargeAction.OnChargeCancel(this, m_EquippedItem);
|
||||
SetHandsIdleAnimation();
|
||||
}
|
||||
|
||||
|
||||
if (RR.World.Context is WorldContext context) {
|
||||
context.FeedbacksManager.HideChargeReadyIndicator();
|
||||
}
|
||||
|
||||
m_IsCharging = false;
|
||||
} else if (m_EquippedItem.Config.canQuickAttack) {
|
||||
if (m_QuickAttackState == QuickAttackState.None) {
|
||||
@@ -307,6 +314,18 @@ namespace RebootReality.jelycho.Player {
|
||||
}
|
||||
}
|
||||
|
||||
void OnChargeReadyAnimation() {
|
||||
if (!m_IsCharging) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_IsSetupAsOwner) {
|
||||
if (RR.World.Context is WorldContext context) {
|
||||
context.FeedbacksManager.ShowChargeReadyIndicator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SecondaryAction() {
|
||||
if (!m_IsSetupAsOwner) {
|
||||
s_Logger.Error("Cannot perform secondary action when not set up as owner.");
|
||||
@@ -338,48 +357,16 @@ namespace RebootReality.jelycho.Player {
|
||||
//
|
||||
// @MARK: Hands animations
|
||||
//
|
||||
void PlayHandsAnimation(string animationName) {
|
||||
// int hash = Animator.StringToHash(animationName);
|
||||
//
|
||||
// if (!m_Animator.HasState(m_HandsLayerIndex, hash)) {
|
||||
// s_Logger.Error($"Animator does not have state with name {animationName}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// PlayHandsAnimation(hash);
|
||||
}
|
||||
|
||||
void PlayHandsAnimation(int animationHash) {
|
||||
// m_Animator.CrossFade(animationHash, 0.0f, m_HandsLayerIndex);
|
||||
//
|
||||
// if (RR.IsServer()) {
|
||||
// PlayerPlayHandsAnimationEvent handsAnimationEvent = new PlayerPlayHandsAnimationEvent {
|
||||
// AnimationHash = animationHash
|
||||
// };
|
||||
// SendActorEvent((byte)PlayerActorEvents.PlayHandsAnimation, ref handsAnimationEvent);
|
||||
// } else {
|
||||
// PlayerActorRequestHandsAnimationCommand handsAnimationCommand =
|
||||
// new PlayerActorRequestHandsAnimationCommand {
|
||||
// AnimationHash = animationHash
|
||||
// };
|
||||
// SendActorCommand((byte) PlayerActorCommands.RequestHandsAnimation, ref handsAnimationCommand);
|
||||
// }
|
||||
}
|
||||
|
||||
void SetHandsIdleAnimation() {
|
||||
m_PlayerAnimator.PlayHandsIdle();
|
||||
}
|
||||
|
||||
void SetChargingAnimation() {
|
||||
if (m_EquippedItem != null) {
|
||||
// PlayHandsAnimation(m_EquippedItem.Config.chargingAnimation);
|
||||
}
|
||||
m_PlayerAnimator.PlayCharging();
|
||||
}
|
||||
|
||||
void SetChargedUseAnimation() {
|
||||
if (m_EquippedItem != null) {
|
||||
// PlayHandsAnimation(m_EquippedItem.Config.chargedUseAnimation);
|
||||
}
|
||||
m_PlayerAnimator.PlayChargedUse();
|
||||
}
|
||||
|
||||
void PlayQuickAttackAnimation(int combo) {
|
||||
@@ -769,6 +756,7 @@ namespace RebootReality.jelycho.Player {
|
||||
|
||||
if (m_EquippedItem != null) {
|
||||
m_PlayerAnimator.SetHandsAnimationSet(m_EquippedItem.Config.handsAnimationClipsSets);
|
||||
SpawnAdditionalEquippedItemActors();
|
||||
} else {
|
||||
m_PlayerAnimator.SetHandsAnimationSet(null);
|
||||
}
|
||||
@@ -776,6 +764,13 @@ namespace RebootReality.jelycho.Player {
|
||||
SetHandsIdleAnimation();
|
||||
}
|
||||
|
||||
void SpawnAdditionalEquippedItemActors() {
|
||||
foreach (ItemActorMountingConfig localMountInfo in m_EquippedItem.Config.additionalActorsToMount) {
|
||||
Actor actor = RR.SpawnLocalOnlyActor(localMountInfo.actor, Vector3.zero, Quaternion.identity);
|
||||
actor.MountTo(this, localMountInfo.slotName);
|
||||
}
|
||||
}
|
||||
|
||||
public void WarpTo(Vector3 position) {
|
||||
if (!RR.IsServer()) {
|
||||
s_Logger.Error("Only the server can warp players.");
|
||||
@@ -789,14 +784,7 @@ namespace RebootReality.jelycho.Player {
|
||||
// @MARK: Common
|
||||
//
|
||||
void TickCharacterRotation() {
|
||||
// @TODO: restore old delayed character rotation
|
||||
m_Locomotion.YawRotation = m_Camera.Yaw;
|
||||
|
||||
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);
|
||||
float angleDeg = Mathf.DeltaAngle(m_Camera.Yaw, m_Locomotion.YawRotation);
|
||||
|
||||
bool rotateCharacter = false;
|
||||
float rotateCharacterSpeed = m_CharacterRotateSpeed;
|
||||
@@ -820,11 +808,9 @@ namespace RebootReality.jelycho.Player {
|
||||
if (rotateCharacter) {
|
||||
m_CharacterTurnVelocity = rotateCharacterSpeed * Time.deltaTime;
|
||||
|
||||
Vector3 newForward = Vector3.RotateTowards(currentCharacterForward,
|
||||
targetCharacterForward,
|
||||
math.radians(m_CharacterTurnVelocity),
|
||||
0.0f);
|
||||
m_CharacterForwardTransform.forward = newForward;
|
||||
m_Locomotion.YawRotation = Mathf.MoveTowardsAngle(m_Locomotion.YawRotation,
|
||||
m_Camera.Yaw,
|
||||
m_CharacterTurnVelocity);
|
||||
}
|
||||
|
||||
// Aim Target adjustment
|
||||
@@ -925,6 +911,9 @@ namespace RebootReality.jelycho.Player {
|
||||
float forwardNormalized = localVelocity.z / m_Locomotion.runSpeed;
|
||||
float rightNormalized = localVelocity.x / m_Locomotion.runSpeed;
|
||||
|
||||
forwardNormalized = math.clamp(forwardNormalized, -1.0f, 1.0f);
|
||||
rightNormalized = math.clamp(rightNormalized, -1.0f, 1.0f);
|
||||
|
||||
float turnVelocity = m_CharacterTurnVelocity;
|
||||
if (math.abs(forwardNormalized) > 0.01f ||
|
||||
math.abs(rightNormalized) > 0.01f ||
|
||||
|
||||
Reference in New Issue
Block a user