Added Attack animation, Fix Edge case for path finding. Added footsteps. Level 2 merge #444

Merged
maverickdgg merged 7 commits from Navigation into main 2023-03-25 16:54:30 +08:00
26 changed files with 1210 additions and 620 deletions

View File

@ -14,13 +14,13 @@ Type: 13
Name: Walk
ID: 229189609
Type: 13
Name: Alerted by Racoon
Name: Alerted_by_Racoon
ID: 227890696
Type: 13
Name: Alerted Idle
Name: Alerted_Idle
ID: 234046577
Type: 13
Name: Alerted Run
Name: Alerted_Run
ID: 230172366
Type: 13
Name: Interact
@ -47,21 +47,21 @@ Type: 13
Name: StunEndBack
ID: 226668516
Type: 13
Name: React to Broken Stuff
Name: React_to_Broken_Stuff
ID: 228323560
Type: 13
Name: Pickup Item
Name: Pickup_Item
ID: 227002263
Type: 13
Name: Return Item
Name: Return_Item
ID: 222655168
Type: 13
Name: Attack Windup
Name: Attack_Windup
ID: 223078653
Type: 13
Name: Attack Hold
Name: Attack_Hold
ID: 228250554
Type: 13
Name: Attack Sequence
Name: Attack_Sequence
ID: 226129627
Type: 13

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,3 +1,3 @@
Name: Level2_AITest_NavData
ID: 255209218
ID: 254149790
Type: 15

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Level2_NavData
ID: 260674210
Type: 15

View File

@ -1,4 +1,4 @@
- NavData: 0
- NavData: 260674210
- EID: 20
Name: ===== Light =====
IsActive: true
@ -5542,19 +5542,61 @@
Position Offset: {x: 0, y: 0.899999976, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Navigation Component:
Target: {x: 0, y: 0, z: 0}
Forward: {x: 0, y: 0, z: 0}
Recalculate Path: true
Unreachable Target: false
Tolerance: 1
Acceptance threshold: 0.100000001
IsActive: true
Animator Component:
Rig: 76586906
AnimationController: 0
IsActive: true
Scripts:
- Type: Homeowner1
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true
waypointsPool: 166
startWaypoint: 162
patrolSpeed: 0.75
chaseSpeed: 2
turningSpeed: 5
sightDistance: 8
eyeOffset: [0, 1.64999998, 0]
distanceToCapture: 0.800000012
captureTime: 0.5
footstepSFXIntervalMultiplier: 0.5
player: 2
range: 5
angle: 30
angleBetween: 0
distance: 0
heightLimit: 1
rayOffset: [0, 0, 0]
withinRange: false
withinSight: false
lastFoundPos: [0, 0, 0]
lastFoundTimer: 0
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
Enabled: true
rotationPerSecond: 5
active: true
rotateToPlayerLastKnown: false
lookAround: false
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI
Enabled: true
idleDuration: 1
timeoutDuration: 2
patrolPointParent: 166
patrolSpeed: 1
chaseSpeed: 3
alertCooldown: 0
player: 2
attackHitbox: 627
walkingAnim: 229189609
idleAnim: 224442713
alertAnim: 227890696
alertRunAnim: 230172366
alertIdleAnim: 234046577
timeoutAnim: 228323560
atkWindupAnim: 223078653
atkHoldAnim: 228250554
atkSeqAnim: 226129627
- Type: StateMachine
Enabled: true
currentStateName: ""
currentAnimName: ""
- EID: 10
Name: Pause Canvas
IsActive: false
@ -5606,7 +5648,7 @@
Components:
Transform Component:
Translate: {x: 0, y: -300, z: 0}
Rotate: {x: 0.5, y: 1.63842165, z: 0.5}
Rotate: {x: -1.48352981, y: 1.63842165, z: 0.5}
Scale: {x: 400, y: 100, z: 500}
IsActive: true
Renderable Component:
@ -6165,7 +6207,7 @@
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 7
Collision Tag: 8
Type: Box
Half Extents: {x: 10, y: 1, z: 18}
Friction: 0.400000006
@ -9263,6 +9305,15 @@
Density: 1
Position Offset: {x: 0.180000007, y: 0.5, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: false
Collision Tag: 9
Type: Box
Half Extents: {x: 2, y: 1, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: -0.100000001}
Rotation Offset: {x: 0, y: 0.922214508, z: 0}
IsActive: true
Scripts: ~
- EID: 204
@ -9299,6 +9350,15 @@
Density: 1
Position Offset: {x: 0.180000007, y: 0.5, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: false
Collision Tag: 9
Type: Box
Half Extents: {x: 1.5, y: 1, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0.200000003, y: 0.5, z: 0.300000012}
Rotation Offset: {x: 0, y: 0.448165625, z: 0}
IsActive: true
Scripts: ~
- EID: 236
@ -10204,6 +10264,15 @@
Density: 1
Position Offset: {x: -0.474999994, y: 0.600000024, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: false
Collision Tag: 9
Type: Box
Half Extents: {x: 4.30000019, y: 1.20000005, z: 1.20000005}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 1.5, y: 0.600000024, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 230
@ -17061,3 +17130,29 @@
Acceleration: {x: 0, y: -0.100000001, z: 0}
IsActive: true
Scripts: ~
- EID: 627
Name: AttackHitbox
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -0.10252738, z: -2.20271254}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: true
Collision Tag: 5
Type: Box
Half Extents: {x: 0.600000024, y: 1.79999995, z: 1.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 1, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox
Enabled: true
aiGO: 158

View File

@ -1,4 +1,4 @@
- NavData: 255209218
- NavData: 254149790
- EID: 20
Name: ===== Light =====
IsActive: true
@ -112,6 +112,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -164,6 +165,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -216,6 +218,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -268,6 +271,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -320,6 +324,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -372,6 +377,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -424,6 +430,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -482,6 +489,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 2
dontReturn: false
soundDistance: 10
@ -702,6 +710,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -754,6 +763,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -806,6 +816,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -858,6 +869,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -910,6 +922,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -962,6 +975,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1014,6 +1028,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1066,6 +1081,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1118,6 +1134,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1170,6 +1187,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1222,6 +1240,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1274,6 +1293,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1326,6 +1346,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1378,6 +1399,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1430,6 +1452,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1482,6 +1505,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1534,6 +1558,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1586,6 +1611,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1638,6 +1664,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1696,6 +1723,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -1748,6 +1776,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -1800,6 +1829,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -1852,6 +1882,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -1904,6 +1935,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -1956,6 +1988,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2014,6 +2047,7 @@
Enabled: true
Score: 500
currCategory: 2
currFood: 0
density: 1
dontReturn: false
soundDistance: 10
@ -2066,6 +2100,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2118,6 +2153,7 @@
Enabled: true
Score: 50
currCategory: 1
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2170,6 +2206,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2222,6 +2259,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2274,6 +2312,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 3
dontReturn: false
soundDistance: 10
@ -2332,6 +2371,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 2
dontReturn: false
soundDistance: 10
@ -2558,6 +2598,7 @@
Enabled: true
Score: 10
currCategory: 0
currFood: 0
density: 2
dontReturn: false
soundDistance: 10
@ -2778,6 +2819,7 @@
Scripts:
- Type: ScoringZone
Enabled: true
startingParticleCount: 10
- EID: 18
Name: CollisionWall
IsActive: true
@ -2841,6 +2883,7 @@
Scripts:
- Type: ScoringZone
Enabled: true
startingParticleCount: 10
- EID: 17
Name: CollisionWall
IsActive: true
@ -3041,8 +3084,6 @@
armLength: 2
turnSpeedPitch: 0.200000003
turnSpeedYaw: 0.400000006
inverseXControls: true
inverseYControls: false
pitchUpperClamp: 45
pitchLowerClamp: 5
- EID: 9
@ -5388,7 +5429,7 @@
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: false
Freeze Rotation Y: true
Freeze Rotation Z: true
IsActive: true
Collider Component:
@ -5396,7 +5437,7 @@
- Is Trigger: false
Collision Tag: 5
Type: Box
Half Extents: {x: 0.600000024, y: 1.79999995, z: 0.400000006}
Half Extents: {x: 0.400000006, y: 1.79999995, z: 0.400000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -5425,9 +5466,6 @@
Enabled: true
currentStateName: ""
currentAnimName: ""
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
Enabled: true
rotationPerSecond: 5
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true
player: 2
@ -5441,6 +5479,9 @@
withinSight: false
lastFoundPos: [0, 0, 0]
lastFoundTimer: 0
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
Enabled: true
rotationPerSecond: 5
- EID: 10
Name: Pause Canvas
IsActive: false

View File

@ -75,7 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
if (hit.Hit && hit.Other != player)
{
Debug.Log("AI LOS: HIT OTHER");
//Debug.Log("AI LOS: HIT OTHER");
withinSight = false;
break;
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
@ -22,12 +18,35 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
public float alertCooldown = 0.0f;
public GameObject player;
public GameObject attackHitbox;
public AnimationClipAsset walkingAnim;
public AnimationClipAsset idleAnim;
public AnimationClipAsset alertAnim;
public AnimationClipAsset alertRunAnim;
public AnimationClipAsset alertIdleAnim;
public AnimationClipAsset timeoutAnim;
public AnimationClipAsset atkWindupAnim;
public AnimationClipAsset atkHoldAnim;
public AnimationClipAsset atkSeqAnim;
private Vector3 startPos;
[NonSerialized]
public IEnumerable<Transform> patrolPointPool;
public void Reset()
{
Transform transform = GetComponent<Transform>();
StateMachine machine = GetScript<StateMachine>();
if (transform && machine)
{
transform.GlobalPosition = startPos;
machine.SetState(typeof(IdleState));
}
}
protected override void awake()
{
@ -40,13 +59,25 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
dictionary.Add(typeof(TimeoutState), new TimeoutState(machine));
dictionary.Add(typeof(ChaseState), new ChaseState(machine));
dictionary.Add(typeof(AlertState), new AlertState(machine));
dictionary.Add(typeof(AttackState), new AttackState(machine));
machine.InitStateMachine(dictionary);
}
AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>();
Transform transform = GetComponent<Transform>();
if (transform)
{
startPos = transform.GlobalPosition;
}
}
protected override void start()
{
attackHitbox.SetActive(false);
}
@ -60,14 +91,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
alertCooldown = 0.0f;
}
RigidBody rigid = GetComponent<RigidBody>();
if(rigid)
{
rigid.AngularVelocity = Vector3.Zero;
}
AICheat();
}
public bool ShouldTransitAlert()
@ -100,6 +124,24 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
}
private void AICheat()
{
StateMachine machine = GetScript<StateMachine>();
if(machine)
{
if (Input.GetKeyDown(Input.KeyCode.F))
{
machine.SetState(typeof(AlertState));
}
if(Input.GetKeyDown(Input.KeyCode.L))
{
machine.SetState(typeof(IdleState));
}
}
}
}
}

View File

@ -0,0 +1,40 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public class HomeOwnerAttackHitbox:Script
{
public GameObject aiGO;
protected override void update()
{
Transform transform = GetComponent<Transform>();
Transform aiTransform = aiGO.GetComponent<Transform>();
if(transform)
{
transform.GlobalPosition = aiTransform.GlobalPosition;
}
}
protected override void onTriggerStay(CollisionInfo info)
{
PlayerController pc = info.GameObject.GetScript<PlayerController>();
HomeOwnerAI ai = aiGO.GetScript<HomeOwnerAI>();
if (pc)
{
pc.GotCaught();
if(ai)
ai.Reset();
}
}
}
}

View File

@ -0,0 +1,3 @@
Name: HomeOwnerAttackHitbox
ID: 164649501
Type: 9

View File

@ -11,23 +11,73 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public float rotationPerSecond = 2.0f;
public bool active = true;
public bool rotateToPlayerLastKnown = false;
public bool lookAround = false;
private bool left = true;
private float lookOffset = 0.0f;
private float lookAroundAngle = 30.0f;
protected override void start()
{
rotateToPlayerLastKnown = false;
active = true;
}
protected override void update()
{
if (!active)
return;
RigidBody rigid = GetComponent<RigidBody>();
Transform transform = GetComponent<Transform>();
if(!lookAround)
{
lookOffset = 0.0f;
}
else
{
if(left )
{
if (lookOffset > -lookAroundAngle)
lookOffset -= rotationPerSecond * Time.DeltaTimeF;
else
left = false;
}
if (!left)
{
if (lookOffset < lookAroundAngle)
lookOffset += rotationPerSecond * Time.DeltaTimeF;
else
left = false;
}
}
if(rigid && transform)
{
Vector3 vel = rigid.LinearVelocity;
rigid.AngularVelocity = Vector3.Zero;
if(vel.GetSqrMagnitude() > 1.0f)
AILineOfSight los = GetScript<AILineOfSight>();
if(los && rotateToPlayerLastKnown)
{
Vector3 direction = los.lastFoundPos - transform.GlobalPosition;
Quaternion currentRotation = transform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z) + lookOffset, 0.0f);
transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF);
return;
}
if(vel.GetMagnitude() > 0.01f)
{
Quaternion currentRotation = transform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z), 0.0f);
transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.FixedDeltaTime);
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f);
transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.DeltaTimeF);
}
}

View File

@ -1,4 +1,5 @@
using System;
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -10,11 +11,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
protected HomeOwnerAI ai;
protected Animator animator;
public AIBaseState(StateMachine stateMachine): base(stateMachine, "")
{
stateName = "AI Base State";
ai = stateMachine.GetScript<HomeOwnerAI>();
animator = stateMachine.GetComponent<Animator>();
}

View File

@ -9,7 +9,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class AlertState: AIBaseState
{
const float alertDuration = 2.0f;
const float alertDuration = 16.0f/30.0f + 1.0f;
float alertTimer = alertDuration;
@ -21,6 +21,15 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter()
{
alertTimer = alertDuration;
if(animator)
{
animator.PlayOneShot(ai.alertAnim);
}
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
@ -30,9 +39,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
machine.SetState(typeof(ChaseState));
}
}
public override void fixedUpdate()
{

View File

@ -0,0 +1,131 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class AttackState: AIBaseState
{
float timer = 0.0f;
float windupTime = 8.0f / 30.0f;
float holdTime = 0.3f;
float seqTime = 8.0f / 30.0f + 0.5f;
bool windUp = false;
bool hold = false;
bool seq = false;
public AttackState(StateMachine machine): base(machine)
{
}
public override void OnEnter()
{
timer = 0.0f;
animator.PlayOneShot(ai.atkWindupAnim);
windUp = true;
hold = false;
seq = false;
timer = windupTime;
RotateToVelocity rotate = machine.GetScript<RotateToVelocity>();
if (rotate)
rotate.active = false;
RigidBody rigid = machine.GetComponent<RigidBody>();
if(rigid)
{
rigid.LinearVelocity = Vector3.Zero;
}
ai.attackHitbox.SetActive(false);
}
public override void OnExit()
{
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.active = true;
rotate.lookAround = false;
}
Transform transform = machine.GetComponent<Transform>();
AILineOfSight los = machine.GetScript<AILineOfSight>();
Transform playerTransform = ai.player.GetComponent<Transform>();
if(los && transform)
{
Vector3 direction = playerTransform.GlobalPosition - transform.GlobalPosition;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f);
transform.LocalRotation = targetRotation;
}
ai.attackHitbox.SetActive(false);
}
public override void update()
{
timer -= Time.DeltaTimeF;
if(windUp)
{
if(timer <= 0.0f)
{
windUp = false;
hold = true;
animator.Play(ai.atkHoldAnim);
timer = holdTime;
ai.attackHitbox.SetActive(true);
}
}
else if(hold)
{
if(timer <= 0.0f)
{
hold = false;
seq = true;
animator.PlayOneShot(ai.atkSeqAnim);
timer = seqTime;
}
}
else if(seq)
{
if(timer <= 0.0f)
{
seq = false;
AILineOfSight los = ai.GetScript<AILineOfSight>();
if(los && los.withinSight)
{
machine.SetState(typeof(ChaseState));
}
else
{
machine.SetState(typeof(TimeoutState));
}
}
}
}
public override void fixedUpdate()
{
}
}
}

View File

@ -0,0 +1,3 @@
Name: AttackState
ID: 156854236
Type: 9

View File

@ -1,4 +1,6 @@
using SHADE;
using SHADE.Test;
using SHADE_Scripting.Audio;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,6 +14,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
float giveUpDuration = 10.0f;
float giveUpTimer = 0.0f;
float atkDistance = 2.0f;
bool run = true;
float footStepInterval = 12.0f / 30.0f;
float footStepTimer = 0.0f;
public ChaseState(StateMachine machine): base(machine)
@ -22,12 +31,39 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter()
{
giveUpTimer = giveUpDuration;
animator.Play(ai.alertRunAnim);
run = true;
RotateToVelocity r = machine.GetScript<RotateToVelocity>();
if (r)
{
r.rotateToPlayerLastKnown = true;
}
footStepTimer = footStepInterval * 0.5f;
}
public override void OnExit()
{
animator.Stop();
RotateToVelocity r = machine.GetScript<RotateToVelocity>();
if (r)
{
r.rotateToPlayerLastKnown = false;
}
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.lookAround = false;
}
}
public override void update()
{
Navigation nav = machine.GetComponent<Navigation>();
AILineOfSight los = ai.GetScript<AILineOfSight>();
RigidBody rigid = machine.GetComponent<RigidBody>();
if (los && nav)
{
Transform playerTransform = los.player.GetComponent<Transform>();
@ -45,13 +81,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
machine.SetState(typeof(TimeoutState));
}
RigidBody rigid = machine.GetComponent<RigidBody>();
if(los.distance < atkDistance)
{
machine.SetState(typeof(AttackState));
}
if(rigid)
{
if (los.withinSight)
rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed;
else
rigid.LinearVelocity = nav.GetForward() * ai.patrolSpeed;
rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed;
}
if(nav.ReachedTarget())
@ -59,12 +100,44 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
giveUpTimer -= Time.DeltaTimeF;
ai.RotateToPlayer();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if(rotate)
{
rotate.lookAround = true;
}
}
}
if (animator && rigid)
{
if (rigid.LinearVelocity.GetMagnitude() < 0.001f)
{
if(run)
{
animator.Play(ai.idleAnim);
run = false;
}
}
else
{
if(!run)
{
animator.Play(ai.alertRunAnim);
run = true;
}
}
}
footStepTimer -= Time.DeltaTimeF;
if (footStepTimer <= 0.0f)
{
footStepTimer += footStepInterval;
AudioHandler.audioClipHandlers["HO_footsteps"].Play();
}
}
public override void fixedUpdate()

View File

@ -23,6 +23,22 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter()
{
timer = 0.0f;
animator.Play(ai.idleAnim);
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.lookAround = true;
}
}
public override void OnExit()
{
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.lookAround = false;
}
}
public override void update()

View File

@ -1,4 +1,5 @@
using SHADE;
using SHADE_Scripting.Audio;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,7 +15,10 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
Vector3 lastFramePos;
float stuckTimer;
bool run = true;
float footStepInterval = 12.0f / 30.0f;
float footStepTimer = 0.0f;
public PatrolState(StateMachine machine) : base(machine)
{
@ -34,7 +38,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
if (dest)
{
nav.MoveTo(dest.GlobalPosition);
Debug.Log("Moving to" + dest.GlobalPosition.ToString());
}
lastFramePos = transform.GlobalPosition;
@ -42,6 +46,24 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
stuckTimer = 0.0f;
}
animator.Play(ai.walkingAnim);
AudioHandler.audioClipHandlers["HO_footsteps"].Play();
footStepTimer = footStepInterval;
RotateToVelocity r = machine.GetScript<RotateToVelocity>();
if(r)
{
r.rotateToPlayerLastKnown = false;
}
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
@ -55,7 +77,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
Vector3 d = lastFramePos - transform.GlobalPosition;
if (d.GetSqrMagnitude() < 0.001f)
{
stuckTimer += Time.DeltaTimeF;
//stuckTimer += Time.DeltaTimeF;
}
@ -75,7 +97,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
machine.SetState(typeof(AlertState));
}
footStepTimer -= Time.DeltaTimeF;
if(footStepTimer <= 0.0f)
{
footStepTimer += footStepInterval;
AudioHandler.audioClipHandlers["HO_footsteps"].Play();
}
}

View File

@ -10,7 +10,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public class TimeoutState : AIBaseState
{
float timer = 0.0f;
float alertCooldown = 10.0f;
float alertCooldown = 1.0f;
public TimeoutState(StateMachine machine) : base(machine)
{
@ -21,6 +21,8 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter()
{
timer = 0.0f;
animator.Play(ai.idleAnim);
}
public override void update()

View File

@ -502,7 +502,7 @@ public class PlayerController : Script
}
}
private void GotCaught()
public void GotCaught()
{
if (currentState == RaccoonStates.CAUGHT && tranform && respawnPoint)
{

View File

@ -262,7 +262,8 @@ namespace SHADE
{
playOnce = false;
isPlaying = false;
currPlaybackTime = currClip->GetStartTimeStamp() + currClip->GetTotalDuration();
const float SINGLE_FRAME_TIME = 1.0f / static_cast<float>(currClip->GetRawAnimation()->GetTicksPerSecond());
currPlaybackTime = currClip->GetStartTimeStamp() + currClip->GetTotalDuration() - SINGLE_FRAME_TIME;
raiseFinishEvent();
}
else

View File

@ -442,6 +442,11 @@ namespace SHADE
if (ImGui::DragScalar("Col", ImGuiDataType_U16, &navSystem->numCols_editor)) {}
if(ImGui::DragScalar("Row", ImGuiDataType_U16, &navSystem->numRows_editor)){}
if (ImGui::Checkbox("Draw Navigation Area", &navSystem->drawNavigationArea)) {}
if (ImGui::Checkbox("Draw Navigation Data", &navSystem->drawNavigationData)) {}
if (ImGui::Checkbox("Draw Path", &navSystem->drawPath)) {}
if (ImGui::Button("Generate"))
{

View File

@ -26,6 +26,11 @@ namespace SHADE
auto id = ComponentFamily::GetID<SHNavigationComponent>();
SHComponentManager::CreateComponentSparseSet<SHNavigationComponent>();
SystemID i = SystemFamily::GetID<SHNavigationSystem>();
//drawNavigationArea = true;
//drawNavigationData = true;
drawPath = true;
}
void SHNavigationSystem::Exit()
@ -213,6 +218,7 @@ namespace SHADE
void SHNavigationSystem::GenerateNavigationGridData() noexcept
{
Clear();
GenerateNavigationGridData(origin_editor, size_editor, numRows_editor, numCols_editor);
}
@ -227,21 +233,20 @@ namespace SHADE
if (editor->editorState != SHEditor::State::PLAY)
{
SHNavigationSystem* system = static_cast<SHNavigationSystem*>(GetSystem());
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::H))
{
system->GenerateNavigationGridData(SHVec3{ 0.0f }, navigationAreaSize, 80, 80);
}
auto debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
if (debugDrawSystem)
{
if (system->drawNavigationArea)
{
SHTransform trans;
trans.position = SHVec3{ 0.0f };
trans.scale = navigationAreaSize;
trans.ComputeTRS();
debugDrawSystem->DrawWireCube(trans.trs, SHColour::YELLOW, false);
#ifdef DRAW_NAVIGATION_DATA
}
if (system->drawNavigationData)
{
for (uint16_t r = 0; r < system->numRows; ++r)
{
for (uint16_t c = 0; c < system->numCols; ++c)
@ -255,7 +260,7 @@ namespace SHADE
topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y };
SHTransform t;
t.position = system->GetGridWorldPos({ r,c });
t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f};
t.scale = SHVec3{ halfGridSize.x * 1.9f, 0.1f, halfGridSize.y * 1.9f };
t.ComputeTRS();
debugDrawSystem->DrawCube(t.trs, SHColour::RED, true);
@ -269,7 +274,7 @@ namespace SHADE
topleft += SHVec3{ c * system->GetGridSize().x, 0.0f, r * system->GetGridSize().y } + SHVec3{ halfGridSize.x,0.0f,halfGridSize.y };
SHTransform t;
t.position = system->GetGridWorldPos({ r,c });
t.scale = SHVec3{ halfGridSize.x * 2.0f, 1.0f, halfGridSize.y * 2.0f };
t.scale = SHVec3{ halfGridSize.x * 1.9f, 0.1f, halfGridSize.y * 1.9f };
t.ComputeTRS();
debugDrawSystem->DrawCube(t.trs, SHColour::WHITE, true);
}
@ -277,11 +282,8 @@ namespace SHADE
}
}
#endif
}
}
}
#endif
}
@ -321,7 +323,10 @@ namespace SHADE
NavigationGridIndex nxtPoint = comp.path.front();
SHVec3 nxtPointPos = GetGridWorldPos(nxtPoint);
SHVec3 direction = nxtPointPos - transform->GetWorldPosition();
NavigationGridIndex currPoint = GetNavigationGridIndex(transform->GetWorldPosition());
SHVec3 currPointPos = GetGridWorldPos(currPoint);
SHVec3 direction = nxtPointPos - currPointPos;
direction.y = 0.0f;
@ -334,12 +339,11 @@ namespace SHADE
//return so we don't run the parts after this twice.
return;
}
comp.forward = SHVec3::Normalise(direction);
#ifdef DRAW_NAVIGATION_PATH
#ifdef SHEDITOR
if (drawPath)
{
auto debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
auto queue = comp.path;
@ -364,7 +368,7 @@ namespace SHADE
}
queue.pop();
}
}
#endif
}
@ -404,6 +408,83 @@ namespace SHADE
NavigationNode startingNode;
startingNode.index = GetNavigationGridIndex(transform->GetWorldPosition());
if (GetNavigationData(startingNode.index) == true)
{
uint16_t i = comp.tolerance;
while (openList.empty())
{
NavigationGridIndex tolCheckIndex = startingNode.index;
tolCheckIndex.row += i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.row -= i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.column += i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.column -= i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.row += i;
tolCheckIndex.column += i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.row -= i;
tolCheckIndex.column -= i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.row -= i;
tolCheckIndex.column += i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
tolCheckIndex = startingNode.index;
tolCheckIndex.row += i;
tolCheckIndex.column -= i;
if (GetNavigationData(tolCheckIndex) == false)
{
startingNode.index = tolCheckIndex;
break;
}
++i;
}
}
startingNode.parent.row = NullGridIndex;
startingNode.parent.column = NullGridIndex;
startingNode.h = std::numeric_limits<uint32_t>::max();
@ -413,6 +494,8 @@ namespace SHADE
openList.push_back(startingNode);
NavigationNode endNode;
endNode.index.row = NullGridIndex;
endNode.index.column = NullGridIndex;

View File

@ -75,6 +75,9 @@ namespace SHADE
AssetID navDataAsset{};
bool drawNavigationArea;
bool drawNavigationData;
bool drawPath;
void GenerateNavigationGridData(SHVec3 origin, SHVec3 size, uint16_t numRow, uint16_t numCol) noexcept;