working on zombie ai

This commit is contained in:
2025-10-10 18:08:54 +02:00
parent 8cee5fbf9e
commit 128166317d
13 changed files with 149 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
{
"version": 1,
"name": "InputSystem_Actions",
"maps": [
{

View File

@@ -0,0 +1,26 @@
using System;
using Unity.Behavior;
using UnityEngine;
using Action = Unity.Behavior.Action;
using Unity.Properties;
[Serializable, GeneratePropertyBag]
[NodeDescription(name: "FindClosestAttackTarget", story: "Agent finds Target", category: "Action", id: "c335cdd99cc546403f5ca3cd5c5e2fa3")]
public partial class FindClosestAttackTargetAction : Action
{
protected override Status OnStart()
{
return Status.Running;
}
protected override Status OnUpdate()
{
return Status.Success;
}
protected override void OnEnd()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fe9e1ad43b36c214389aa56933a4b4f9

View File

@@ -1,5 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using Animancer;
using RebootKit.Engine.AI;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Main;
using RebootKit.Engine.Network;
@@ -9,8 +11,8 @@ using TriInspector;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using Logger = RebootKit.Engine.Foundation.Logger;
using UnityEvent = UnityEngine.Events.UnityEvent;
namespace RebootReality.jelycho.Enemies {
public class ZombieActorData : IActorData {
@@ -59,6 +61,10 @@ namespace RebootReality.jelycho.Enemies {
}
}
public class ZombieBlackboard {
public ZombieActor Self;
}
[DeclareBoxGroup("Body parts")]
public class ZombieActor : Actor, IKillable {
static readonly Logger s_Logger = new Logger(nameof(ZombieActor));
@@ -74,7 +80,7 @@ namespace RebootReality.jelycho.Enemies {
Berserk
}
[SerializeField] Animator m_Animator;
[SerializeField] AnimancerComponent m_Animancer;
[SerializeField] NavMeshAgent m_NavAgent;
@@ -99,11 +105,23 @@ namespace RebootReality.jelycho.Enemies {
public UnityEvent died = new UnityEvent();
BehaviourTree m_BehaviourTree;
//
// @MARK: Unity callbacks
//
void Awake() {
SetRagdollLocal(false);
m_BehaviourTree = new BehaviourTree("Zombie Behaviour");
var rootSelector = new Selector("Root");
m_BehaviourTree.AddChild(rootSelector);
var attackPlayerSequence = new Sequence("Attack Player",
() => m_PlayerTarget != null);
rootSelector.AddChild(attackPlayerSequence);
}
//
@@ -117,7 +135,7 @@ namespace RebootReality.jelycho.Enemies {
}
float velXZ = m_NavAgent.velocity.With(y: 0).magnitude;
m_Animator.SetFloat(s_MovementSpeedHash, velXZ);
// m_Animator.SetFloat(s_MovementSpeedHash, velXZ);
}
public override void OnServerTick(float deltaTime) {
@@ -128,6 +146,9 @@ namespace RebootReality.jelycho.Enemies {
return;
}
m_BehaviourTree.Process(deltaTime);
return;
switch (m_State) {
case AIState.Idle: {
ServerTickIdle(deltaTime);
@@ -190,7 +211,7 @@ namespace RebootReality.jelycho.Enemies {
if (distToPlayerSq <= m_MaxAttackDistance * m_MaxAttackDistance) {
m_NextAttackTimer -= dt;
if (m_NextAttackTimer <= 0.0f) {
m_Animator.CrossFade("Attack_0", 0.0f, 0);
// m_Animator.CrossFade("Attack_0", 0.0f, 0);
m_NextAttackTimer = m_AttackDelay;
}
@@ -284,7 +305,7 @@ namespace RebootReality.jelycho.Enemies {
ragdollRigidbody.isKinematic = !active;
}
m_Animator.enabled = !active;
m_Animancer.enabled = !active;
}
//

View File

@@ -19,7 +19,8 @@
"GUID:f2be1b7392ef6cc4eafd0ee8ac7a090a",
"GUID:f0ca7da2c713f5849a8e3326866a5e49",
"GUID:7f7d1af65c2641843945d409d28f2e20",
"GUID:4c25c05f410a3a447a75c3b0909152ef"
"GUID:4c25c05f410a3a447a75c3b0909152ef",
"GUID:73907d139b13f8a43b7e3e95c329d30a"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -967,8 +967,8 @@ MonoBehaviour:
m_ActorPrefabReference:
m_AssetGUID: cc37529a52919b443aa04c484902cb68
m_SubObjectName:
m_SubObjectGUID:
m_SubObjectType:
m_SubObjectGUID:
m_EditorAssetChanged: 0
m_Count: 1
m_SpawnPoints: []
@@ -1340,8 +1340,8 @@ MonoBehaviour:
m_ActorPrefabReference:
m_AssetGUID: 0258297780346e648b9fca3bb5f89543
m_SubObjectName:
m_SubObjectGUID:
m_SubObjectType:
m_SubObjectGUID:
m_EditorAssetChanged: 0
m_Count: 1
m_SpawnPoints: []
@@ -3682,8 +3682,8 @@ MonoBehaviour:
m_ActorPrefabReference:
m_AssetGUID: 50a5e87baaedf5b46ba52646e8e88b74
m_SubObjectName:
m_SubObjectGUID:
m_SubObjectType:
m_SubObjectGUID:
m_EditorAssetChanged: 0
m_Count: 10
m_SpawnPoints: []
@@ -6441,7 +6441,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 807751232810720550, guid: 2bc4b78daa0582a41a43d02ae219339a, type: 3}
propertyPath: m_LocalPosition.x
value: 7.63
value: 1.7
objectReference: {fileID: 0}
- target: {fileID: 807751232810720550, guid: 2bc4b78daa0582a41a43d02ae219339a, type: 3}
propertyPath: m_LocalPosition.y
@@ -6449,7 +6449,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 807751232810720550, guid: 2bc4b78daa0582a41a43d02ae219339a, type: 3}
propertyPath: m_LocalPosition.z
value: -18.03
value: 17.32
objectReference: {fileID: 0}
- target: {fileID: 807751232810720550, guid: 2bc4b78daa0582a41a43d02ae219339a, type: 3}
propertyPath: m_LocalRotation.w

View File

@@ -60,7 +60,7 @@ MonoBehaviour:
syncRotation: 1
syncScale: 0
m_AttachmentSockets: []
m_Animator: {fileID: 9202368008358846522}
m_Animancer: {fileID: 1454564773443580898}
m_NavAgent: {fileID: 8828257924038919546}
m_RootCollider: {fileID: 1135518741664066520}
m_RagdollRigidbodies:
@@ -600,6 +600,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: d2e957dad22ca1f4fae5e5e9fd8170c3, type: 3}
insertIndex: -1
addedObject: {fileID: 9202368008358846522}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: d2e957dad22ca1f4fae5e5e9fd8170c3, type: 3}
insertIndex: -1
addedObject: {fileID: 1454564773443580898}
- targetCorrespondingSourceObject: {fileID: 1082271958561512970, guid: d2e957dad22ca1f4fae5e5e9fd8170c3, type: 3}
insertIndex: -1
addedObject: {fileID: 4485639414822483688}
@@ -1592,7 +1595,7 @@ Animator:
m_GameObject: {fileID: 5437166838216447403}
m_Enabled: 1
m_Avatar: {fileID: 9000000, guid: e74130c49b009364f90d176af44766be, type: 3}
m_Controller: {fileID: 9100000, guid: ed07376a401151c47a47c0dfb496fc99, type: 2}
m_Controller: {fileID: 0}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
@@ -1604,6 +1607,21 @@ Animator:
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!114 &1454564773443580898
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5437166838216447403}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0ad50f81b1d25c441943c37a89ba23f6, type: 3}
m_Name:
m_EditorClassIdentifier:
_Animator: {fileID: 9202368008358846522}
_Transitions: {fileID: 0}
_ActionOnDisable: 0
--- !u!4 &6614165842428853091 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -7169757591262751847, guid: d2e957dad22ca1f4fae5e5e9fd8170c3, type: 3}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: abbbab8942b837447b27aaabda26e5ae
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,6 +8,7 @@
"com.unity.addressables": "2.7.3",
"com.unity.ai.navigation": "2.0.9",
"com.unity.animation.rigging": "1.3.0",
"com.unity.behavior": "1.0.12",
"com.unity.cinemachine": "3.1.3",
"com.unity.collab-proxy": "2.9.3",
"com.unity.ide.rider": "3.0.38",

View File

@@ -90,6 +90,23 @@
},
"url": "https://packages.unity.com"
},
"com.unity.behavior": {
"version": "1.0.12",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.7.2",
"com.unity.dt.app-ui": "2.0.0-pre.16",
"com.unity.modules.ai": "1.0.0",
"com.unity.collections": "2.1.4",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.bindings.openimageio": {
"version": "1.0.0",
"depth": 1,
@@ -138,6 +155,18 @@
},
"url": "https://packages.unity.com"
},
"com.unity.dt.app-ui": {
"version": "2.0.0-pre.16",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.screencapture": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.ext.nunit": {
"version": "2.0.5",
"depth": 1,

View File

@@ -0,0 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 53
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6118340bc55d5fc4b88ef6970b16d122, type: 3}
m_Name:
m_EditorClassIdentifier:
m_GraphOwnerName: Self
m_AutoSaveLastSaveLocation: 1
m_SaveFolder: jelycho/Code/Enemies
m_UseSeparateSaveFolders: 0
m_SaveFolderAction:
m_SaveFolderModifier:
m_SaveFolderFlow:
m_SaveFolderCondition:
m_SaveFolderEventChannels:
m_SaveFolderEnum:
m_AutoOpenNodeScriptsInExternalEditor: 1
m_Namespace:
m_AllowDisabledAgentDebugging: 0

View File

@@ -13,6 +13,7 @@ EditorBuildSettings:
guid: 99c9720ab356a0642a771bea13969a05
m_configObjects:
com.unity.addressableassets: {fileID: 11400000, guid: 67d4bf55309dfa94da71f2a2ffe64204, type: 2}
com.unity.dt.app-ui: {fileID: 11400000, guid: 99f9c9493070a9d4c979a8fec7c5a8d3, type: 2}
com.unity.input.settings: {fileID: 11400000, guid: 5e0d3796a45800e429656e78e50c710e, type: 2}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 052faaac586de48259a63d0c4782560b, type: 3}
m_UseUCBPForAssetBundles: 0

View File

@@ -13,6 +13,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
shaderVariantLimit: 128
overrideShaderVariantLimit: 0
customInterpolatorErrorThreshold: 32
customInterpolatorWarningThreshold: 16
customHeatmapValues: {fileID: 0}