Added Attack animation, Fix Edge case for path finding. Added footsteps. Level 2 merge #444
|
@ -1,3 +1,3 @@
|
|||
Name: Level2_AITest_NavData
|
||||
ID: 258243609
|
||||
ID: 254149790
|
||||
Type: 15
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: Level2_NavData
|
||||
ID: 267663500
|
||||
Type: 15
|
|
@ -1,4 +1,4 @@
|
|||
- NavData: 0
|
||||
- NavData: 267663500
|
||||
- EID: 20
|
||||
Name: ===== Light =====
|
||||
IsActive: true
|
||||
|
@ -3144,8 +3144,6 @@
|
|||
armLength: 2
|
||||
turnSpeedPitch: 0.200000003
|
||||
turnSpeedYaw: 0.400000006
|
||||
inverseXControls: false
|
||||
inverseYControls: false
|
||||
pitchUpperClamp: 45
|
||||
pitchLowerClamp: 5
|
||||
- EID: 9
|
||||
|
@ -5547,7 +5545,7 @@
|
|||
- EID: 158
|
||||
Name: ====AI=====
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
NumberOfChildren: 2
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: 0, z: -2.93461704}
|
||||
|
@ -5585,19 +5583,99 @@
|
|||
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: StateMachine
|
||||
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
|
||||
currentStateName: ""
|
||||
currentAnimName: ""
|
||||
- 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: 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
|
||||
Name: Pause Canvas
|
||||
IsActive: false
|
||||
|
@ -5649,7 +5727,7 @@
|
|||
Components:
|
||||
Transform Component:
|
||||
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}
|
||||
IsActive: true
|
||||
Renderable Component:
|
||||
|
@ -6208,7 +6286,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
|
||||
|
@ -9206,7 +9284,7 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
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}
|
||||
Scale: {x: 0.999974966, y: 1, z: 0.999974966}
|
||||
IsActive: true
|
||||
|
@ -9242,7 +9320,7 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
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}
|
||||
Scale: {x: 0.999929309, y: 1, z: 0.999929309}
|
||||
IsActive: true
|
||||
|
@ -9306,6 +9384,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: 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
|
||||
Scripts: ~
|
||||
- EID: 204
|
||||
|
@ -9342,6 +9429,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, 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
|
||||
Scripts: ~
|
||||
- EID: 236
|
||||
|
@ -10247,6 +10343,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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- NavData: 258243609
|
||||
- NavData: 254149790
|
||||
- EID: 20
|
||||
Name: ===== Light =====
|
||||
IsActive: true
|
||||
|
@ -5429,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:
|
||||
|
@ -5437,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
|
||||
|
@ -5466,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
|
||||
|
@ -5482,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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,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 +63,23 @@ 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
RigidBody rigid = GetComponent<RigidBody>();
|
||||
if(rigid)
|
||||
{
|
||||
rigid.AngularVelocity = Vector3.Zero;
|
||||
}
|
||||
|
||||
|
||||
AICheat();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
Name: HomeOwnerAttackHitbox
|
||||
ID: 164649501
|
||||
Type: 9
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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>();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
Name: AttackState
|
||||
ID: 156854236
|
||||
Type: 9
|
|
@ -1,4 +1,5 @@
|
|||
using SHADE;
|
||||
using SHADE.Test;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -12,6 +13,10 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
|
|||
|
||||
float giveUpDuration = 10.0f;
|
||||
float giveUpTimer = 0.0f;
|
||||
float atkDistance = 2.0f;
|
||||
|
||||
|
||||
bool run = true;
|
||||
|
||||
|
||||
public ChaseState(StateMachine machine): base(machine)
|
||||
|
@ -22,12 +27,36 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
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 +74,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,7 +93,34 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
|
|||
Vector3 lastFramePos;
|
||||
|
||||
float stuckTimer ;
|
||||
|
||||
bool run = true;
|
||||
|
||||
public PatrolState(StateMachine machine) : base(machine)
|
||||
{
|
||||
|
@ -34,7 +34,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 +42,21 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
|
|||
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()
|
||||
|
@ -55,7 +70,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
|
|||
Vector3 d = lastFramePos - transform.GlobalPosition;
|
||||
if (d.GetSqrMagnitude() < 0.001f)
|
||||
{
|
||||
stuckTimer += Time.DeltaTimeF;
|
||||
//stuckTimer += Time.DeltaTimeF;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace SHADE
|
|||
SHComponentManager::CreateComponentSparseSet<SHNavigationComponent>();
|
||||
SystemID i = SystemFamily::GetID<SHNavigationSystem>();
|
||||
|
||||
drawNavigationArea = true;
|
||||
drawNavigationData = true;
|
||||
//drawNavigationArea = true;
|
||||
//drawNavigationData = 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 };
|
||||
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);
|
||||
|
||||
|
@ -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 };
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue