Merge pull request #444 from SHADE-DP/Navigation

Added Attack animation, Fix Edge case for path finding. Added footsteps. Level 2 merge
This commit is contained in:
XiaoQiDigipen 2023-03-25 16:54:30 +08:00 committed by GitHub
commit 4f84736599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1210 additions and 620 deletions

View File

@ -14,13 +14,13 @@ Type: 13
Name: Walk Name: Walk
ID: 229189609 ID: 229189609
Type: 13 Type: 13
Name: Alerted by Racoon Name: Alerted_by_Racoon
ID: 227890696 ID: 227890696
Type: 13 Type: 13
Name: Alerted Idle Name: Alerted_Idle
ID: 234046577 ID: 234046577
Type: 13 Type: 13
Name: Alerted Run Name: Alerted_Run
ID: 230172366 ID: 230172366
Type: 13 Type: 13
Name: Interact Name: Interact
@ -47,21 +47,21 @@ Type: 13
Name: StunEndBack Name: StunEndBack
ID: 226668516 ID: 226668516
Type: 13 Type: 13
Name: React to Broken Stuff Name: React_to_Broken_Stuff
ID: 228323560 ID: 228323560
Type: 13 Type: 13
Name: Pickup Item Name: Pickup_Item
ID: 227002263 ID: 227002263
Type: 13 Type: 13
Name: Return Item Name: Return_Item
ID: 222655168 ID: 222655168
Type: 13 Type: 13
Name: Attack Windup Name: Attack_Windup
ID: 223078653 ID: 223078653
Type: 13 Type: 13
Name: Attack Hold Name: Attack_Hold
ID: 228250554 ID: 228250554
Type: 13 Type: 13
Name: Attack Sequence Name: Attack_Sequence
ID: 226129627 ID: 226129627
Type: 13 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 Name: Level2_AITest_NavData
ID: 255209218 ID: 254149790
Type: 15 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 - EID: 20
Name: ===== Light ===== Name: ===== Light =====
IsActive: true IsActive: true
@ -5542,19 +5542,61 @@
Position Offset: {x: 0, y: 0.899999976, z: 0} Position Offset: {x: 0, y: 0.899999976, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true 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: Scripts:
- Type: Homeowner1 - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true Enabled: true
waypointsPool: 166 player: 2
startWaypoint: 162 range: 5
patrolSpeed: 0.75 angle: 30
chaseSpeed: 2 angleBetween: 0
turningSpeed: 5 distance: 0
sightDistance: 8 heightLimit: 1
eyeOffset: [0, 1.64999998, 0] rayOffset: [0, 0, 0]
distanceToCapture: 0.800000012 withinRange: false
captureTime: 0.5 withinSight: false
footstepSFXIntervalMultiplier: 0.5 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 - EID: 10
Name: Pause Canvas Name: Pause Canvas
IsActive: false IsActive: false
@ -5606,7 +5648,7 @@
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: -300, z: 0} 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} Scale: {x: 400, y: 100, z: 500}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
@ -6165,7 +6207,7 @@
Collider Component: Collider Component:
Colliders: Colliders:
- Is Trigger: false - Is Trigger: false
Collision Tag: 7 Collision Tag: 8
Type: Box Type: Box
Half Extents: {x: 10, y: 1, z: 18} Half Extents: {x: 10, y: 1, z: 18}
Friction: 0.400000006 Friction: 0.400000006
@ -9263,6 +9305,15 @@
Density: 1 Density: 1
Position Offset: {x: 0.180000007, y: 0.5, z: 0} Position Offset: {x: 0.180000007, y: 0.5, z: 0}
Rotation Offset: {x: 0, y: 0, 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 IsActive: true
Scripts: ~ Scripts: ~
- EID: 204 - EID: 204
@ -9299,6 +9350,15 @@
Density: 1 Density: 1
Position Offset: {x: 0.180000007, y: 0.5, z: 0} Position Offset: {x: 0.180000007, y: 0.5, z: 0}
Rotation Offset: {x: 0, y: 0, 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 IsActive: true
Scripts: ~ Scripts: ~
- EID: 236 - EID: 236
@ -10204,6 +10264,15 @@
Density: 1 Density: 1
Position Offset: {x: -0.474999994, y: 0.600000024, z: 0} Position Offset: {x: -0.474999994, y: 0.600000024, z: 0}
Rotation Offset: {x: 0, y: 0, 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 IsActive: true
Scripts: ~ Scripts: ~
- EID: 230 - EID: 230
@ -17061,3 +17130,29 @@
Acceleration: {x: 0, y: -0.100000001, z: 0} Acceleration: {x: 0, y: -0.100000001, z: 0}
IsActive: true IsActive: true
Scripts: ~ 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 - EID: 20
Name: ===== Light ===== Name: ===== Light =====
IsActive: true IsActive: true
@ -112,6 +112,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -164,6 +165,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -216,6 +218,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -268,6 +271,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -320,6 +324,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -372,6 +377,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -424,6 +430,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -482,6 +489,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 2 density: 2
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -702,6 +710,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -754,6 +763,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -806,6 +816,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -858,6 +869,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -910,6 +922,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -962,6 +975,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1014,6 +1028,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1066,6 +1081,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1118,6 +1134,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1170,6 +1187,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1222,6 +1240,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1274,6 +1293,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1326,6 +1346,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1378,6 +1399,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1430,6 +1452,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1482,6 +1505,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1534,6 +1558,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1586,6 +1611,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1638,6 +1664,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1696,6 +1723,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1748,6 +1776,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1800,6 +1829,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1852,6 +1882,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1904,6 +1935,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -1956,6 +1988,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2014,6 +2047,7 @@
Enabled: true Enabled: true
Score: 500 Score: 500
currCategory: 2 currCategory: 2
currFood: 0
density: 1 density: 1
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2066,6 +2100,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2118,6 +2153,7 @@
Enabled: true Enabled: true
Score: 50 Score: 50
currCategory: 1 currCategory: 1
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2170,6 +2206,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2222,6 +2259,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2274,6 +2312,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 3 density: 3
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2332,6 +2371,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 2 density: 2
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2558,6 +2598,7 @@
Enabled: true Enabled: true
Score: 10 Score: 10
currCategory: 0 currCategory: 0
currFood: 0
density: 2 density: 2
dontReturn: false dontReturn: false
soundDistance: 10 soundDistance: 10
@ -2778,6 +2819,7 @@
Scripts: Scripts:
- Type: ScoringZone - Type: ScoringZone
Enabled: true Enabled: true
startingParticleCount: 10
- EID: 18 - EID: 18
Name: CollisionWall Name: CollisionWall
IsActive: true IsActive: true
@ -2841,6 +2883,7 @@
Scripts: Scripts:
- Type: ScoringZone - Type: ScoringZone
Enabled: true Enabled: true
startingParticleCount: 10
- EID: 17 - EID: 17
Name: CollisionWall Name: CollisionWall
IsActive: true IsActive: true
@ -3041,8 +3084,6 @@
armLength: 2 armLength: 2
turnSpeedPitch: 0.200000003 turnSpeedPitch: 0.200000003
turnSpeedYaw: 0.400000006 turnSpeedYaw: 0.400000006
inverseXControls: true
inverseYControls: false
pitchUpperClamp: 45 pitchUpperClamp: 45
pitchLowerClamp: 5 pitchLowerClamp: 5
- EID: 9 - EID: 9
@ -5388,7 +5429,7 @@
Freeze Position Y: false Freeze Position Y: false
Freeze Position Z: false Freeze Position Z: false
Freeze Rotation X: true Freeze Rotation X: true
Freeze Rotation Y: false Freeze Rotation Y: true
Freeze Rotation Z: true Freeze Rotation Z: true
IsActive: true IsActive: true
Collider Component: Collider Component:
@ -5396,7 +5437,7 @@
- Is Trigger: false - Is Trigger: false
Collision Tag: 5 Collision Tag: 5
Type: Box 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 Friction: 0.400000006
Bounciness: 0 Bounciness: 0
Density: 1 Density: 1
@ -5425,9 +5466,6 @@
Enabled: true Enabled: true
currentStateName: "" currentStateName: ""
currentAnimName: "" currentAnimName: ""
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
Enabled: true
rotationPerSecond: 5
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true Enabled: true
player: 2 player: 2
@ -5441,6 +5479,9 @@
withinSight: false withinSight: false
lastFoundPos: [0, 0, 0] lastFoundPos: [0, 0, 0]
lastFoundTimer: 0 lastFoundTimer: 0
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
Enabled: true
rotationPerSecond: 5
- EID: 10 - EID: 10
Name: Pause Canvas Name: Pause Canvas
IsActive: false IsActive: false

View File

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

View File

@ -1,11 +1,7 @@
using System; using System;
using System.Collections.Generic; 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;
using SHADE_Scripting.Audio;
using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States; using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
@ -22,12 +18,35 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
public float alertCooldown = 0.0f; public float alertCooldown = 0.0f;
public GameObject player; 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] [NonSerialized]
public IEnumerable<Transform> patrolPointPool; 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() protected override void awake()
{ {
@ -40,13 +59,25 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
dictionary.Add(typeof(TimeoutState), new TimeoutState(machine)); dictionary.Add(typeof(TimeoutState), new TimeoutState(machine));
dictionary.Add(typeof(ChaseState), new ChaseState(machine)); dictionary.Add(typeof(ChaseState), new ChaseState(machine));
dictionary.Add(typeof(AlertState), new AlertState(machine)); dictionary.Add(typeof(AlertState), new AlertState(machine));
dictionary.Add(typeof(AttackState), new AttackState(machine));
machine.InitStateMachine(dictionary); machine.InitStateMachine(dictionary);
} }
AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>(); 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; alertCooldown = 0.0f;
} }
AICheat();
RigidBody rigid = GetComponent<RigidBody>();
if(rigid)
{
rigid.AngularVelocity = Vector3.Zero;
}
} }
public bool ShouldTransitAlert() 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 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() protected override void update()
{ {
if (!active)
return;
RigidBody rigid = GetComponent<RigidBody>(); RigidBody rigid = GetComponent<RigidBody>();
Transform transform = GetComponent<Transform>(); 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) if(rigid && transform)
{ {
Vector3 vel = rigid.LinearVelocity; 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 currentRotation = transform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z), 0.0f); Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 0.0f);
transform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationPerSecond * (float)Time.FixedDeltaTime); 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,11 +11,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{ {
protected HomeOwnerAI ai; protected HomeOwnerAI ai;
protected Animator animator;
public AIBaseState(StateMachine stateMachine): base(stateMachine, "") public AIBaseState(StateMachine stateMachine): base(stateMachine, "")
{ {
stateName = "AI Base State"; stateName = "AI Base State";
ai = stateMachine.GetScript<HomeOwnerAI>(); 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 public class AlertState: AIBaseState
{ {
const float alertDuration = 2.0f; const float alertDuration = 16.0f/30.0f + 1.0f;
float alertTimer = alertDuration; float alertTimer = alertDuration;
@ -21,6 +21,15 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter() public override void OnEnter()
{ {
alertTimer = alertDuration; alertTimer = alertDuration;
if(animator)
{
animator.PlayOneShot(ai.alertAnim);
}
}
public override void OnExit()
{
animator.Stop();
} }
public override void update() public override void update()
@ -30,9 +39,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{ {
machine.SetState(typeof(ChaseState)); machine.SetState(typeof(ChaseState));
} }
} }
public override void fixedUpdate() 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;
using SHADE.Test;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,6 +14,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
float giveUpDuration = 10.0f; float giveUpDuration = 10.0f;
float giveUpTimer = 0.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) public ChaseState(StateMachine machine): base(machine)
@ -22,12 +31,39 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter() public override void OnEnter()
{ {
giveUpTimer = giveUpDuration; 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() public override void update()
{ {
Navigation nav = machine.GetComponent<Navigation>(); Navigation nav = machine.GetComponent<Navigation>();
AILineOfSight los = ai.GetScript<AILineOfSight>(); AILineOfSight los = ai.GetScript<AILineOfSight>();
RigidBody rigid = machine.GetComponent<RigidBody>();
if (los && nav) if (los && nav)
{ {
Transform playerTransform = los.player.GetComponent<Transform>(); Transform playerTransform = los.player.GetComponent<Transform>();
@ -45,13 +81,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
machine.SetState(typeof(TimeoutState)); machine.SetState(typeof(TimeoutState));
} }
RigidBody rigid = machine.GetComponent<RigidBody>(); if(los.distance < atkDistance)
{
machine.SetState(typeof(AttackState));
}
if(rigid) if(rigid)
{ {
if (los.withinSight) if (los.withinSight)
rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed; rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed;
else else
rigid.LinearVelocity = nav.GetForward() * ai.patrolSpeed; rigid.LinearVelocity = nav.GetForward() * ai.chaseSpeed;
} }
if(nav.ReachedTarget()) if(nav.ReachedTarget())
@ -59,12 +100,44 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
giveUpTimer -= Time.DeltaTimeF; giveUpTimer -= Time.DeltaTimeF;
ai.RotateToPlayer(); 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() public override void fixedUpdate()

View File

@ -23,6 +23,22 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter() public override void OnEnter()
{ {
timer = 0.0f; 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() public override void update()

View File

@ -1,4 +1,5 @@
using SHADE; using SHADE;
using SHADE_Scripting.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -14,7 +15,10 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
Vector3 lastFramePos; Vector3 lastFramePos;
float stuckTimer; float stuckTimer;
bool run = true;
float footStepInterval = 12.0f / 30.0f;
float footStepTimer = 0.0f;
public PatrolState(StateMachine machine) : base(machine) public PatrolState(StateMachine machine) : base(machine)
{ {
@ -34,7 +38,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
if (dest) if (dest)
{ {
nav.MoveTo(dest.GlobalPosition); nav.MoveTo(dest.GlobalPosition);
Debug.Log("Moving to" + dest.GlobalPosition.ToString());
} }
lastFramePos = transform.GlobalPosition; lastFramePos = transform.GlobalPosition;
@ -42,6 +46,24 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
stuckTimer = 0.0f; 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() public override void update()
@ -55,7 +77,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
Vector3 d = lastFramePos - transform.GlobalPosition; Vector3 d = lastFramePos - transform.GlobalPosition;
if (d.GetSqrMagnitude() < 0.001f) 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)); 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 public class TimeoutState : AIBaseState
{ {
float timer = 0.0f; float timer = 0.0f;
float alertCooldown = 10.0f; float alertCooldown = 1.0f;
public TimeoutState(StateMachine machine) : base(machine) public TimeoutState(StateMachine machine) : base(machine)
{ {
@ -21,6 +21,8 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnEnter() public override void OnEnter()
{ {
timer = 0.0f; timer = 0.0f;
animator.Play(ai.idleAnim);
} }
public override void update() 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) if (currentState == RaccoonStates.CAUGHT && tranform && respawnPoint)
{ {

View File

@ -262,7 +262,8 @@ namespace SHADE
{ {
playOnce = false; playOnce = false;
isPlaying = 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(); raiseFinishEvent();
} }
else else

View File

@ -442,6 +442,11 @@ namespace SHADE
if (ImGui::DragScalar("Col", ImGuiDataType_U16, &navSystem->numCols_editor)) {} if (ImGui::DragScalar("Col", ImGuiDataType_U16, &navSystem->numCols_editor)) {}
if(ImGui::DragScalar("Row", ImGuiDataType_U16, &navSystem->numRows_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")) if (ImGui::Button("Generate"))
{ {

View File

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

View File

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