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
20 changed files with 522 additions and 55 deletions
Showing only changes of commit 47f195e998 - Show all commits

View File

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

Binary file not shown.

View File

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

View File

@ -1,4 +1,4 @@
- NavData: 0 - NavData: 267663500
- EID: 20 - EID: 20
Name: ===== Light ===== Name: ===== Light =====
IsActive: true IsActive: true
@ -3144,8 +3144,6 @@
armLength: 2 armLength: 2
turnSpeedPitch: 0.200000003 turnSpeedPitch: 0.200000003
turnSpeedYaw: 0.400000006 turnSpeedYaw: 0.400000006
inverseXControls: false
inverseYControls: false
pitchUpperClamp: 45 pitchUpperClamp: 45
pitchLowerClamp: 5 pitchLowerClamp: 5
- EID: 9 - EID: 9
@ -5547,7 +5545,7 @@
- EID: 158 - EID: 158
Name: ====AI===== Name: ====AI=====
IsActive: true IsActive: true
NumberOfChildren: 0 NumberOfChildren: 2
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 0, z: -2.93461704} Translate: {x: 0, y: 0, z: -2.93461704}
@ -5585,19 +5583,99 @@
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: StateMachine
Enabled: true Enabled: true
waypointsPool: 166 currentStateName: ""
startWaypoint: 162 currentAnimName: ""
patrolSpeed: 0.75 - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.RotateToVelocity
chaseSpeed: 2 Enabled: true
turningSpeed: 5 rotationPerSecond: 5
sightDistance: 8 active: true
eyeOffset: [0, 1.64999998, 0] rotateToPlayerLastKnown: false
distanceToCapture: 0.800000012 lookAround: false
captureTime: 0.5 - Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI
footstepSFXIntervalMultiplier: 0.5 Enabled: true
idleDuration: 1
timeoutDuration: 2
patrolPointParent: 166
patrolSpeed: 1
chaseSpeed: 3
alertCooldown: 0
player: 2
attackHitbox: 612
walkingAnim: 229189609
idleAnim: 224442713
alertAnim: 227890696
alertRunAnim: 230172366
alertIdleAnim: 234046577
timeoutAnim: 219563559
atkWindupAnim: 223078653
atkHoldAnim: 228250554
atkSeqAnim: 226129627
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true
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
- EID: 612
Name: AttackHitbox
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
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.800000012, y: 1.79999995, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.899999976, z: 0.400000006}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 610
Name: Net
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 0
Material: 0
IsActive: true
Scripts: ~
- EID: 10 - EID: 10
Name: Pause Canvas Name: Pause Canvas
IsActive: false IsActive: false
@ -5649,7 +5727,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: 0.5, z: 0.5} Rotate: {x: -1.48352981, y: 0.5, 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:
@ -6208,7 +6286,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
@ -9206,7 +9284,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: -0.901912689, y: -2.37551575e-07, z: 0.00345230103} Translate: {x: -0.75174284, y: -2.38418579e-07, z: 0.09204638}
Rotate: {x: -0, y: 1.95162022, z: 0} Rotate: {x: -0, y: 1.95162022, z: 0}
Scale: {x: 0.999974966, y: 1, z: 0.999974966} Scale: {x: 0.999974966, y: 1, z: 0.999974966}
IsActive: true IsActive: true
@ -9242,7 +9320,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: -0.180002213, y: 0, z: -0.507282257} Translate: {x: -0.180002213, y: 0, z: -0.452192545}
Rotate: {x: -0, y: 2.26356983, z: 0} Rotate: {x: -0, y: 2.26356983, z: 0}
Scale: {x: 0.999929309, y: 1, z: 0.999929309} Scale: {x: 0.999929309, y: 1, z: 0.999929309}
IsActive: true IsActive: true
@ -9306,6 +9384,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: 0.600000024, y: 1, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.699999988, z: -0.100000001}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 204 - EID: 204
@ -9342,6 +9429,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, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.400000006, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 236 - EID: 236
@ -10247,6 +10343,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

View File

@ -1,4 +1,4 @@
- NavData: 258243609 - NavData: 254149790
- EID: 20 - EID: 20
Name: ===== Light ===== Name: ===== Light =====
IsActive: true IsActive: true
@ -5429,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:
@ -5437,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
@ -5466,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
@ -5482,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

@ -22,12 +22,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 +63,23 @@ 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);
} }
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 +93,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 +126,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,26 @@
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
{
protected override void onCollisionEnter(CollisionInfo info)
{
PlayerController pc = info.GameObject.GetScript<PlayerController>();
HomeOwnerAI ai = GameObject.Parent.GetScript<HomeOwnerAI>();
if (pc && ai)
{
Debug.Log("HomeOwnerAttackHitbox: Player caught");
}
}
}
}

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,124 @@
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;
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,5 @@
using SHADE; using SHADE;
using SHADE.Test;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,6 +13,10 @@ 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;
public ChaseState(StateMachine machine): base(machine) public ChaseState(StateMachine machine): base(machine)
@ -22,13 +27,37 @@ 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;
}
}
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>();
if(los && nav) RigidBody rigid = machine.GetComponent<RigidBody>();
if (los && nav)
{ {
Transform playerTransform = los.player.GetComponent<Transform>(); Transform playerTransform = los.player.GetComponent<Transform>();
if (los.withinSight) if (los.withinSight)
@ -45,13 +74,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,7 +93,34 @@ 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;
}
} }

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

@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
Vector3 lastFramePos; Vector3 lastFramePos;
float stuckTimer ; float stuckTimer ;
bool run = true;
public PatrolState(StateMachine machine) : base(machine) public PatrolState(StateMachine machine) : base(machine)
{ {
@ -34,7 +34,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 +42,21 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
stuckTimer = 0.0f; stuckTimer = 0.0f;
} }
animator.Play(ai.walkingAnim);
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 +70,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;
} }

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

@ -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

@ -27,8 +27,8 @@ namespace SHADE
SHComponentManager::CreateComponentSparseSet<SHNavigationComponent>(); SHComponentManager::CreateComponentSparseSet<SHNavigationComponent>();
SystemID i = SystemFamily::GetID<SHNavigationSystem>(); SystemID i = SystemFamily::GetID<SHNavigationSystem>();
drawNavigationArea = true; //drawNavigationArea = true;
drawNavigationData = true; //drawNavigationData = true;
drawPath = true; drawPath = true;
} }
@ -259,7 +259,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);
@ -273,7 +273,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);
} }