working on enemies

This commit is contained in:
2025-08-20 05:06:00 +02:00
parent f6a4db7b4d
commit fb1c3f8290
619 changed files with 46709 additions and 668 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using R3;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Foundation;
@@ -14,7 +15,7 @@ using UnityEngine.AddressableAssets;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootReality.jelycho.Player {
public class PlayerActor : Actor {
public class PlayerActor : Actor, IKillable {
static readonly Logger s_Logger = new Logger(nameof(PlayerActor));
[SerializeField] PlayerAnimator m_PlayerAnimator;
@@ -33,6 +34,7 @@ namespace RebootReality.jelycho.Player {
[SerializeField] float m_RunCameraBobbing = 0.5f;
[SerializeField] float m_IdleCameraBobbing = 0.0f;
[SerializeField] float m_CameraBobbingTransitionSpeed = 5.0f;
[SerializeField] float m_TurnTransitionSpeed = 5.0f;
float m_TargetCameraBobbing = 0.0f;
float m_CurrentCameraBobbing = 0.0f;
@@ -50,6 +52,7 @@ namespace RebootReality.jelycho.Player {
[SerializeField] float m_CharacterRotateFastSpeed = 720.0f;
float m_CharacterTurnVelocity = 0.0f;
float m_CharacterTurnVelocitySmooth = 0.0f;
[Header("Animations")]
[SerializeField] int m_HandsLayerIndex;
@@ -115,6 +118,8 @@ namespace RebootReality.jelycho.Player {
}
}
List<Actor> m_AdditionalMountedActor = new List<Actor>();
protected override IActorData CreateActorData() {
return new PlayerActorData { };
}
@@ -198,6 +203,14 @@ namespace RebootReality.jelycho.Player {
}
}
public void Kick() {
if (!m_IsSetupAsOwner) {
return;
}
m_PlayerAnimator.PlayKickAnimation();
}
public void BeginPrimaryAction() {
if (!m_IsSetupAsOwner) {
s_Logger.Error("Cannot begin primary action when not set up as owner.");
@@ -504,7 +517,7 @@ namespace RebootReality.jelycho.Player {
}
if (targetActor is IKillable killable) {
killable.OnHit(this, 100.0f);
killable.OnHit(this, 100);
}
break;
@@ -724,6 +737,7 @@ namespace RebootReality.jelycho.Player {
item.SetHidden(true);
SendInventoryState();
UpdateEquippedItem();
}
void UpdateEquippedItem() {
@@ -759,18 +773,31 @@ namespace RebootReality.jelycho.Player {
SpawnAdditionalEquippedItemActors();
} else {
m_PlayerAnimator.SetHandsAnimationSet(null);
DestroyAdditionalEquippedItemActors();
}
SetHandsIdleAnimation();
}
void SpawnAdditionalEquippedItemActors() {
DestroyAdditionalEquippedItemActors();
foreach (ItemActorMountingConfig localMountInfo in m_EquippedItem.Config.additionalActorsToMount) {
Actor actor = RR.SpawnLocalOnlyActor(localMountInfo.actor, Vector3.zero, Quaternion.identity);
actor.MountTo(this, localMountInfo.slotName);
m_AdditionalMountedActor.Add(actor);
}
}
void DestroyAdditionalEquippedItemActors() {
foreach (Actor actor in m_AdditionalMountedActor) {
RR.DestroyActor(actor);
}
m_AdditionalMountedActor.Clear();
}
public void WarpTo(Vector3 position) {
if (!RR.IsServer()) {
s_Logger.Error("Only the server can warp players.");
@@ -780,6 +807,17 @@ namespace RebootReality.jelycho.Player {
m_Locomotion.WarpTo(position);
}
//
// @MARK: IKillable
//
public bool IsAlive() {
return true;
}
public ulong OnHit(Actor attacker, ulong damage) {
return 0;
}
//
// @MARK: Common
//
@@ -807,6 +845,7 @@ namespace RebootReality.jelycho.Player {
if (rotateCharacter) {
m_CharacterTurnVelocity = rotateCharacterSpeed * Time.deltaTime;
m_CharacterTurnVelocitySmooth = m_CharacterTurnVelocity;
m_Locomotion.YawRotation = Mathf.MoveTowardsAngle(m_Locomotion.YawRotation,
m_Camera.Yaw,
@@ -914,20 +953,23 @@ namespace RebootReality.jelycho.Player {
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 ||
!m_Locomotion.IsGrounded) {
turnVelocity = 0.0f;
m_CharacterTurnVelocitySmooth = 0.0f;
}
PlayerLocomotionAnimatorParams locomotionParams = new PlayerLocomotionAnimatorParams {
IsGrounded = m_Locomotion.IsGrounded,
VelocityForwardNormalized = forwardNormalized,
VelocityRightNormalized = rightNormalized,
TurnVelocity = turnVelocity
TurnVelocity = m_CharacterTurnVelocitySmooth
};
m_PlayerAnimator.SetLocomotionParams(locomotionParams);
m_CharacterTurnVelocitySmooth = Mathf.MoveTowards(m_CharacterTurnVelocitySmooth,
0.0f,
m_TurnTransitionSpeed * Time.deltaTime);
}
}

View File

@@ -1,11 +1,8 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using RebootKit.Engine.Animations;
using RebootReality.jelycho.Items;
using Unity.Mathematics;
using UnityEditor.Search;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
@@ -32,7 +29,7 @@ namespace RebootReality.jelycho.Player {
[SerializeField] AnimationClip m_TurnLeftClip;
[SerializeField] float m_TransitionSpeed = 5.0f;
[SerializeField, Range(0.0f, 1.0f)] float m_ForceIdleMagnitudeThreshold = 0.2f;
AnimationMixerPlayable m_Mixer;
float2 m_TargetInput;
float2 m_CurrentInput;
@@ -53,14 +50,16 @@ namespace RebootReality.jelycho.Player {
m_Mixer.SetInputWeight(i, 0.0f);
}
float turnWeight = math.clamp(math.abs(m_Turning), 0.0f, 1.0f);
if (m_Turning > 0.1f) {
m_Mixer.SetInputWeight(5, 1.0f);
m_Mixer.SetInputWeight(5, turnWeight);
} else if (m_Turning < -0.1f) {
m_Mixer.SetInputWeight(6, 1.0f);
} else {
m_Mixer.SetInputWeight(0, 1.0f);
m_Mixer.SetInputWeight(6, turnWeight);
}
m_Mixer.SetInputWeight(0, 1.0f - turnWeight);
return;
}
@@ -278,11 +277,14 @@ namespace RebootReality.jelycho.Player {
public class PlayerAnimator : MonoBehaviour {
[SerializeField] ReAnimator m_ReAnimator;
[SerializeField] int m_HandsLayerIndex = 2;
MixerNode m_LocomotionRootMixer;
LayerMixerNode m_LegsLayerMixer;
BasicCharacterLocomotionReAnimatorNode m_GroundBlendTree;
CharacterHandsReAnimatorNode m_Hands;
AnimationClipNode m_QuickKickNode;
// @TODO: for some reason `SetLocomotionParams` is called before awake
bool m_IsReady = false;
@@ -290,17 +292,20 @@ namespace RebootReality.jelycho.Player {
public UnityEvent onChargeReady = new UnityEvent();
void Awake() {
m_LocomotionRootMixer = m_ReAnimator.FindNode<MixerNode>("locomotion_root");
m_LocomotionRootMixer.SetInputWeight(0, 1.0f);
m_LocomotionRootMixer.SetInputWeight(1, 0.0f);
m_LegsLayerMixer = m_ReAnimator.FindNode<LayerMixerNode>("legs_mixer");
m_LegsLayerMixer.SetLayerWeight(0, 1.0f);
m_LegsLayerMixer.SetLayerWeight(1, 0.0f);
m_LegsLayerMixer.SetLayerWeight(2, 0.0f);
m_GroundBlendTree = m_ReAnimator.FindNode<BasicCharacterLocomotionReAnimatorNode>("locomotion_ground");
m_GroundBlendTree = m_ReAnimator.FindNode<BasicCharacterLocomotionReAnimatorNode>("legs_locomotion_ground");
m_GroundBlendTree.SetInput(new float2(0, 0), 0.0f);
m_Hands = m_ReAnimator.FindNode<CharacterHandsReAnimatorNode>("hands");
m_Hands.OnQuickAttackAnimationFinished += () => { onQuickAttackFinished?.Invoke(); };
m_Hands.OnCharged += () => { onChargeReady?.Invoke(); };
m_QuickKickNode = m_ReAnimator.FindNode<AnimationClipNode>("legs_kick_quick");
m_IsReady = true;
}
@@ -311,8 +316,7 @@ namespace RebootReality.jelycho.Player {
return;
}
m_LocomotionRootMixer.SetInputWeight(0, locomotionParams.IsGrounded ? 1.0f : 0.0f);
m_LocomotionRootMixer.SetInputWeight(1, locomotionParams.IsGrounded ? 0.0f : 1.0f);
m_LegsLayerMixer.SetLayerWeight(1, locomotionParams.IsGrounded ? 0.0f : 1.0f);
float2 groundBlendDirection = new float2(locomotionParams.VelocityRightNormalized,
locomotionParams.VelocityForwardNormalized);
@@ -321,11 +325,11 @@ namespace RebootReality.jelycho.Player {
public void SetHandsAnimationSet(ItemHandsAnimationClipsSet clipsSet) {
if (clipsSet == null) {
m_ReAnimator.SetLayerWeight(1, 0.0f);
m_ReAnimator.SetLayerWeight(m_HandsLayerIndex, 0.0f);
return;
}
m_ReAnimator.SetLayerWeight(1, 1.0f);
m_ReAnimator.SetLayerWeight(m_HandsLayerIndex, 1.0f);
m_Hands.UpdateClips(clipsSet);
}
@@ -344,5 +348,13 @@ namespace RebootReality.jelycho.Player {
public void PlayChargedUse() {
m_Hands.PlayChargedUse();
}
public void PlayKickAnimation() {
m_LegsLayerMixer.SetLayerWeight(2, 1.0f);
m_QuickKickNode.PlayOnceWithCallback(() => {
m_LegsLayerMixer.SetLayerWeight(2, 0.0f);
});
}
}
}

View File

@@ -120,6 +120,10 @@ namespace RebootReality.jelycho.Player {
m_Actor.DropItem();
}
if (m_Config.kickActionReference.action.WasReleasedThisFrame()) {
m_Actor.Kick();
}
if (m_Config.primaryActionReference.action.WasPressedThisFrame()) {
m_Actor.BeginPrimaryAction();
}
@@ -164,8 +168,8 @@ namespace RebootReality.jelycho.Player {
public InputActionReference lookActionReference;
public InputActionReference jumpActionReference;
public InputActionReference sprintActionReference;
public InputActionReference dragObjectActionReference;
public InputActionReference dropItemActionReference;
public InputActionReference kickActionReference;
public InputActionReference primaryActionReference;
public InputActionReference secondaryActionReference;
public InputActionReference interactActionReference;