ai fix along wit new music

This commit is contained in:
Glence 2023-03-26 13:27:42 +08:00
parent 44bbdf5f82
commit 2da73f12d0
10 changed files with 361 additions and 337 deletions

Binary file not shown.

View File

@ -9354,7 +9354,7 @@
- Is Trigger: true
Collision Tag: 5
Type: Box
Half Extents: {x: 0.600000024, y: 1.79999995, z: 1.5}
Half Extents: {x: 1, y: 1.79999995, z: 1.5}
Friction: 0.400000006
Bounciness: 0
Density: 1

View File

@ -17145,7 +17145,7 @@
- Is Trigger: true
Collision Tag: 5
Type: Box
Half Extents: {x: 0.600000024, y: 1.79999995, z: 1.5}
Half Extents: {x: 1, y: 1.79999995, z: 1.5}
Friction: 0.400000006
Bounciness: 0
Density: 1

View File

@ -6,7 +6,7 @@
Components:
Transform Component:
Translate: {x: -4.64838362, y: 2.94342947, z: 0.209690213}
Rotate: {x: 0.5, y: 0.5, z: 6.5}
Rotate: {x: -1.48352981, y: 0.5, z: 6.5}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Light Component:
@ -8951,7 +8951,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.806008875, y: 0, z: 1.30613756}
Translate: {x: 4.1322155, y: 0, z: 1.85982013}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -8962,7 +8962,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.513795853, y: 0, z: 5.17213631}
Translate: {x: 3.66769528, y: 0, z: 5.17213631}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -8973,7 +8973,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.497500449, y: 0, z: 7.26010561}
Translate: {x: 5.12931681, y: 0, z: 7.53852272}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -8984,7 +8984,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.380023897, y: 0, z: 9.58513737}
Translate: {x: 5.37614918, y: 0, z: 9.58513737}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -8995,7 +8995,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 4.76827145, y: 0, z: 9.12785816}
Translate: {x: -0.473824114, y: 0, z: 9.12785816}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -9006,7 +9006,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 5.0583787, y: 0, z: 4.71819115}
Translate: {x: -0.366229892, y: 0, z: 4.99889755}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -9017,7 +9017,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.53010821, y: 0, z: 4.63929033}
Translate: {x: 0.666945934, y: 0, z: 4.45493603}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -9028,7 +9028,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.64600039, y: 0, z: 2.86434269}
Translate: {x: 0.605797768, y: 0, z: 2.86434269}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -9039,7 +9039,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.50184393, y: 0, z: 0.390250444}
Translate: {x: 0.566371024, y: 0, z: 1.71020806}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -15112,7 +15112,7 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.667429447, y: 0, z: 1.10868871}
Translate: {x: 3.96016145, y: 0, z: 1.54417288}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
@ -15217,7 +15217,7 @@
- Is Trigger: true
Collision Tag: 5
Type: Box
Half Extents: {x: 0.800000012, y: 1.79999995, z: 1.5}
Half Extents: {x: 1, y: 1.79999995, z: 1.5}
Friction: 0.400000006
Bounciness: 0
Density: 1

View File

@ -6,145 +6,148 @@ using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public class HomeOwnerAI:Script
public class HomeOwnerAI : Script
{
public float idleDuration = 1.0f;
public float timeoutDuration = 2.0f;
public GameObject patrolPointParent;
public float patrolSpeed = 2.0f;
public float chaseSpeed = 3.0f;
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;
public bool atk { get; set; }
[NonSerialized]
public IEnumerable<Transform> patrolPointPool;
public void Reset()
{
public float idleDuration = 1.0f;
public float timeoutDuration = 2.0f;
public GameObject patrolPointParent;
public float patrolSpeed = 2.0f;
public float chaseSpeed = 3.0f;
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));
}
}
Transform transform = GetComponent<Transform>();
StateMachine machine = GetScript<StateMachine>();
if (transform && machine)
{
transform.GlobalPosition = startPos;
machine.SetState(typeof(IdleState));
}
}
protected override void awake()
{
StateMachine machine = GetScript<StateMachine>();
if(machine)
{
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
dictionary.Add(typeof(IdleState), new IdleState(machine));
dictionary.Add(typeof(PatrolState), new PatrolState(machine));
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));
protected override void awake()
{
StateMachine machine = GetScript<StateMachine>();
if (machine)
{
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
dictionary.Add(typeof(IdleState), new IdleState(machine));
dictionary.Add(typeof(PatrolState), new PatrolState(machine));
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);
}
machine.InitStateMachine(dictionary);
}
AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
AudioHandler.audioClipHandlers["HO_footsteps"] = SHADE.Audio.CreateAudioClip("event:/Homeowner/homeowner_footsteps");
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>();
Transform transform = GetComponent<Transform>();
if (transform)
{
startPos = transform.GlobalPosition;
}
}
protected override void start()
{
attackHitbox.SetActive(false);
}
protected override void update()
{
if(alertCooldown > 0.0f)
{
alertCooldown -= Time.DeltaTimeF;
}
else
{
alertCooldown = 0.0f;
}
AICheat();
}
public bool ShouldTransitAlert()
{
AILineOfSight los = GetScript<AILineOfSight>();
if (los)
{
if (los.withinSight && alertCooldown <= 0.0f)
{
return true;
}
}
return false;
}
public void RotateToPlayer()
{
//Transform playerTransform = player.GetComponent<Transform>();
////Rotate to face player.
//Transform aiTransform = GetComponent<Transform>();
//if(playerTransform && aiTransform)
//{
// Vector3 direction = playerTransform.GlobalPosition - aiTransform.GlobalPosition;
// Quaternion currentRotation = aiTransform.LocalRotation;
// Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f);
// aiTransform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, 5.0f * (float)Time.FixedDeltaTime);
//}
}
private void AICheat()
{
StateMachine machine = GetScript<StateMachine>();
AILineOfSight los = GetScript<AILineOfSight>();
if(machine && los)
{
if (Input.GetKeyDown(Input.KeyCode.K))
{
los.range = 5.0f;
machine.SetState(typeof(AlertState));
}
if(Input.GetKeyDown(Input.KeyCode.L))
{
los.range = 0.0f;
machine.SetState(typeof(IdleState));
}
}
}
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>();
Transform transform = GetComponent<Transform>();
if (transform)
{
startPos = transform.GlobalPosition;
}
atk = false;
}
protected override void start()
{
//attackHitbox.SetActive(false);
}
protected override void update()
{
if (alertCooldown > 0.0f)
{
alertCooldown -= Time.DeltaTimeF;
}
else
{
alertCooldown = 0.0f;
}
AICheat();
}
public bool ShouldTransitAlert()
{
AILineOfSight los = GetScript<AILineOfSight>();
if (los)
{
if (los.withinSight && alertCooldown <= 0.0f)
{
return true;
}
}
return false;
}
public void RotateToPlayer()
{
//Transform playerTransform = player.GetComponent<Transform>();
////Rotate to face player.
//Transform aiTransform = GetComponent<Transform>();
//if(playerTransform && aiTransform)
//{
// Vector3 direction = playerTransform.GlobalPosition - aiTransform.GlobalPosition;
// Quaternion currentRotation = aiTransform.LocalRotation;
// Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f);
// aiTransform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, 5.0f * (float)Time.FixedDeltaTime);
//}
}
private void AICheat()
{
StateMachine machine = GetScript<StateMachine>();
AILineOfSight los = GetScript<AILineOfSight>();
if (machine && los)
{
if (Input.GetKeyDown(Input.KeyCode.K))
{
los.range = 5.0f;
machine.SetState(typeof(AlertState));
}
if (Input.GetKeyDown(Input.KeyCode.L))
{
los.range = 0.0f;
machine.SetState(typeof(IdleState));
}
}
}
}
}

View File

@ -13,14 +13,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public GameObject aiGO;
Transform transform;
Transform aiTransform;
private bool raccoonFound = false;
Transform transform;
Transform aiTransform;
private PlayerController pc;
private HomeOwnerAI ai;
protected override void start()
{
transform = GetComponent<Transform>();
aiTransform = aiGO.GetComponent<Transform>();
transform = GetComponent<Transform>();
aiTransform = aiGO.GetComponent<Transform>();
ai = aiGO.GetScript<HomeOwnerAI>();
}
protected override void update()
@ -32,27 +36,26 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
transform.GlobalEulerAngles = aiTransform.GlobalEulerAngles;
}
if (raccoonFound && pc && ai)
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
ai.Reset();
raccoonFound = false;
}
}
protected override void onTriggerStay(CollisionInfo info)
{
PlayerController pc = info.GameObject.GetScript<PlayerController>();
HomeOwnerAI ai = aiGO.GetScript<HomeOwnerAI>();
if (pc)
pc = info.GameObject.GetScript<PlayerController>();
if (ai && ai.atk && pc)
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
if (ai)
{
ai.Reset();
GameObject.SetActive(false);
}
raccoonFound = true;
}
}

View File

@ -4,52 +4,55 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE_Scripting.Audio;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class AlertState: AIBaseState
public class AlertState : AIBaseState
{
const float alertDuration = 16.0f / 30.0f + 1.0f;
float alertTimer = alertDuration;
public AlertState(StateMachine machine) : base(machine)
{
const float alertDuration = 16.0f/30.0f + 1.0f;
float alertTimer = alertDuration;
public AlertState(StateMachine machine): base(machine)
{
stateName = "Alert";
}
public override void OnEnter()
{
alertTimer = alertDuration;
if(animator)
{
animator.PlayOneShot(ai.alertAnim);
}
SHADE.Audio.SetParameterWithLabel("PlayerDetection", "Detected");
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
{
alertTimer -= Time.DeltaTimeF;
if (alertTimer <= 0.0f)
{
machine.SetState(typeof(ChaseState));
}
}
public override void fixedUpdate()
{
}
stateName = "Alert";
AudioHandler.audioClipHandlers["raccoondetected"] = SHADE.Audio.CreateAudioClip("event:/Raccoon/raccoon_detected");
}
public override void OnEnter()
{
alertTimer = alertDuration;
if (animator)
{
animator.PlayOneShot(ai.alertAnim);
}
SHADE.Audio.SetParameterWithLabel("PlayerDetection", "Detected");
AudioHandler.audioClipHandlers["raccoondetected"].Play();
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
{
alertTimer -= Time.DeltaTimeF;
if (alertTimer <= 0.0f)
{
machine.SetState(typeof(ChaseState));
}
}
public override void fixedUpdate()
{
}
}
}

View File

@ -7,145 +7,149 @@ using System.Threading.Tasks;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class AttackState: AIBaseState
public class AttackState : AIBaseState
{
float timer = 0.0f;
float windupTime = 8.0f / 30.0f;
float holdTime = 0.3f;
float seqTime = 8.0f / 30.0f;
float endTime = 0.5f;
bool windUp = false;
bool hold = false;
bool seq = false;
bool end = false;
public AttackState(StateMachine machine) : base(machine)
{
float timer = 0.0f;
float windupTime = 8.0f / 30.0f;
float holdTime = 0.3f;
float seqTime = 8.0f / 30.0f ;
float endTime = 0.5f;
}
bool windUp = false;
bool hold = false;
bool seq = false;
bool end = false;
public override void OnEnter()
{
timer = 0.0f;
animator.PlayOneShot(ai.atkWindupAnim);
windUp = true;
hold = false;
seq = false;
end = false;
timer = windupTime;
public AttackState(StateMachine machine): base(machine)
{
RotateToVelocity rotate = machine.GetScript<RotateToVelocity>();
if (rotate)
rotate.active = false;
}
RigidBody rigid = machine.GetComponent<RigidBody>();
if (rigid)
{
rigid.LinearVelocity = Vector3.Zero;
}
Transform transform = machine.GetComponent<Transform>();
AILineOfSight los = machine.GetScript<AILineOfSight>();
Transform playerTransform = ai.player.GetComponent<Transform>();
public override void OnEnter()
{
timer = 0.0f;
animator.PlayOneShot(ai.atkWindupAnim);
windUp = true;
hold = false;
seq = false;
end = false;
timer = windupTime;
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;
RotateToVelocity rotate = machine.GetScript<RotateToVelocity>();
if (rotate)
rotate.active = false;
}
RigidBody rigid = machine.GetComponent<RigidBody>();
if(rigid)
{
rigid.LinearVelocity = Vector3.Zero;
}
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 OnExit()
{
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.active = true;
rotate.lookAround = false;
}
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 <= 1.0f / 30.0f)
{
ai.attackHitbox.SetActive(true);
}
if(timer <= 0.0f)
{
seq = false;
end = true;
timer = endTime;
}
}
else if(end)
{
if(timer <= 0.0f)
{
end = false;
AILineOfSight los = ai.GetScript<AILineOfSight>();
if (los && los.withinSight)
{
machine.SetState(typeof(ChaseState));
}
else
{
machine.SetState(typeof(TimeoutState));
}
}
}
}
public override void fixedUpdate()
{
}
//ai.attackHitbox.SetActive(false);
}
public override void OnExit()
{
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
rotate.active = true;
rotate.lookAround = false;
}
//ai.attackHitbox.SetActive(false);
machine.GetScript<HomeOwnerAI>().atk = 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);
//machine.GetScript<HomeOwnerAI>().atk = true;
}
}
else if (hold)
{
if (timer <= 0.0f)
{
hold = false;
seq = true;
animator.PlayOneShot(ai.atkSeqAnim);
timer = seqTime;
}
}
else if (seq)
{
if (timer <= 1.0f / 30.0f)
{
//ai.attackHitbox.SetActive(true);
machine.GetScript<HomeOwnerAI>().atk = true;
}
if (timer <= 0.0f)
{
seq = false;
end = true;
timer = endTime;
}
}
else if (end)
{
if (timer <= 0.0f)
{
end = 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

@ -1,5 +1,6 @@
using SHADE;
using SHADE_Scripting.Audio;
using SHADE_Scripting.Gameplay.AIBehaviour.AIRework;
using System;
public class Item : Script
{
@ -155,7 +156,7 @@ public class Item : Script
emitter.Emit();
}
if (info.GameObject.GetScript<Homeowner1>() && homeownerOnce)
if (info.GameObject.GetScript<HomeOwnerAI>() && homeownerOnce)
{
homeownerOnce = false;
returnBack = true;

View File

@ -51,6 +51,8 @@ public class GameManager : Script
private bool goingToWin;
private bool goingToLose;
private bool playSpeedUp = false;
protected override void awake()
{
if (Instance != null && Instance != this)
@ -91,6 +93,7 @@ public class GameManager : Script
AudioHandler.audioClipHandlers["SFXItemScore"] = Audio.CreateAudioClip("event:/Music/stingers/item_scored");
AudioHandler.audioClipHandlers["RaccoonScored"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_scored");
Audio.SetParameterWithLabel("PlaybackSpeed", "Normal");
}
protected override void start()
@ -123,6 +126,13 @@ public class GameManager : Script
if (currGameState == GameState.START)
{
timer -= Time.DeltaTimeF;
if (timer < 30.0f && !playSpeedUp)
{
Audio.SetParameterWithLabel("PlaybackSpeed", "ToTransition");
playSpeedUp = true;
}
if(scoreText)
scoreText.GetComponent<TextRenderable>().Text = $"{Score}";
if(timeText)