Added CaughtRaccoon state to AI FSM #449

Merged
maverickdgg merged 5 commits from Navigation into main 2023-03-31 17:05:28 +08:00
10 changed files with 120 additions and 31 deletions
Showing only changes of commit 8c5bf82aa5 - Show all commits

View File

@ -5911,6 +5911,7 @@
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAI
Enabled: true
idleDuration: 1
caughtDuration: 2
timeoutDuration: 2
patrolPointParent: 166
patrolSpeed: 1
@ -17271,3 +17272,4 @@
- Type: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.HomeOwnerAttackHitbox
Enabled: true
aiGO: 158
raccoonFound: false

View File

@ -10,6 +10,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
public class HomeOwnerAI : Script
{
public float idleDuration = 1.0f;
public float caughtDuration = 2.0f;
public float timeoutDuration = 2.0f;
public GameObject patrolPointParent;
@ -41,6 +42,9 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
private Transform transform;
[NonSerialized]
public HomeOwnerAttackHitbox hitboxScript;
public void Reset()
{
StateMachine machine = GetScript<StateMachine>();
@ -65,6 +69,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
dictionary.Add(typeof(ChaseState), new ChaseState(machine));
dictionary.Add(typeof(AlertState), new AlertState(machine));
dictionary.Add(typeof(AttackState), new AttackState(machine));
dictionary.Add(typeof(CaughtRaccoonState), new CaughtRaccoonState(machine));
machine.InitStateMachine(dictionary);
}
@ -84,6 +89,11 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
//attackHitbox.SetActive(false);
if (pppList != null)
startPos = pppList[0].LocalPosition;
if (attackHitbox)
hitboxScript = attackHitbox.GetScript<HomeOwnerAttackHitbox>();
}

View File

@ -13,11 +13,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public GameObject aiGO;
private bool raccoonFound = false;
public bool raccoonFound = false;
Transform transform;
Transform aiTransform;
private PlayerController pc;
[NonSerialized]
public PlayerController pc;
private HomeOwnerAI ai;
protected override void start()
@ -39,20 +40,18 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
if (raccoonFound && pc && ai)
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
if (!ai.atk)
raccoonFound = false;
pc.GotCaught();
ai.Reset();
raccoonFound = false;
}
}
protected override void onTriggerStay(CollisionInfo info)
{
pc = info.GameObject.GetScript<PlayerController>();
if(info.GameObject.GetScript<PlayerController>())
pc = info.GameObject.GetScript<PlayerController>();
if (ai && ai.atk && pc)
{
raccoonFound = true;

View File

@ -37,23 +37,23 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
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;
}
}
//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;
// }
//}
@ -75,7 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
if(vel.GetMagnitude() > 0.01f)
{
Quaternion currentRotation = transform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(vel.x, vel.z) + lookOffset, 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.DeltaTimeF);
}
}

View File

@ -26,7 +26,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public AttackState(StateMachine machine) : base(machine)
{
stateName = "Attack";
}
@ -68,7 +68,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void OnExit()
{
animator.Stop();
RotateToVelocity rotate = ai.GetScript<RotateToVelocity>();
if (rotate)
{
@ -84,6 +84,12 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
public override void update()
{
if (ai.hitboxScript.raccoonFound)
{
machine.SetState(typeof(CaughtRaccoonState));
}
timer -= Time.DeltaTimeF;
if (windUp)
{
@ -141,9 +147,13 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
machine.SetState(typeof(TimeoutState));
}
}
}
}
public override void fixedUpdate()

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
using static PlayerController;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
public class CaughtRaccoonState: AIBaseState
{
private float timer = 0.0f;
private PlayerController pc;
public CaughtRaccoonState(StateMachine machine):base(machine)
{
stateName = "Caught Raccoon";
}
public override void OnEnter()
{
if(ai.hitboxScript)
pc = ai.hitboxScript.pc;
timer = ai.caughtDuration;
}
public override void OnExit()
{
animator.Stop();
}
public override void update()
{
timer -= Time.DeltaTimeF;
if(timer <= 0.0f)
{
if (pc)
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
}
ai.Reset();
}
}
public override void fixedUpdate()
{
}
}
}

View File

@ -0,0 +1,3 @@
Name: CaughtRaccoonState
ID: 153010954
Type: 9

View File

@ -14,7 +14,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
float giveUpDuration = 10.0f;
float giveUpTimer = 0.0f;
float atkDistance = 2.0f;
float atkDistance = 1.0f;
bool run = true;

View File

@ -8,6 +8,7 @@ struct MatPropData
int textureIndex;
float alpha;
float sliderThreshold;
float borderThickness;
vec4 sliderStartColor;
vec4 sliderEndColor;
vec4 sliderBarColor;
@ -43,6 +44,8 @@ void main()
{
//fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
if (In.uv.x > MatProp.data[In2.materialIndex].sliderThreshold)
fragColor = MatProp.data[In2.materialIndex].sliderBarColor;
else