Navigation and AI merge for level 3 #445

Merged
maverickdgg merged 6 commits from Navigation into main 2023-03-25 18:49:20 +08:00
8 changed files with 202 additions and 84 deletions

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Level3_NavData
ID: 263362242
Type: 15

View File

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

View File

@ -1,4 +1,4 @@
- NavData: 0
- NavData: 263362242
- EID: 0
Name: Light_Direction
IsActive: true
@ -4573,6 +4573,15 @@
Density: 1
Position Offset: {x: 0.284000009, y: 0.305999994, z: 0.555999994}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: false
Collision Tag: 9
Type: Box
Half Extents: {x: 1.70000005, y: 1, z: 1.79999995}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: -0.200000003, y: 0.200000003, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 206
@ -5696,7 +5705,7 @@
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 7
Collision Tag: 8
Type: Box
Half Extents: {x: 15, y: 1, z: 15}
Friction: 0.400000006
@ -8930,60 +8939,6 @@
Clicked: false
IsActive: true
Scripts: ~
- EID: 542
Name: ====AI=====
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 1.19757175, y: 0, z: 0.855755448}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 148542784
Material: 121518381
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.100000001
Gravity Scale: 1
Use Gravity: true
Interpolate: false
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: false
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 5
Type: Box
Half Extents: {x: 0.600000024, y: 1.79999995, z: 0.400000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0.899999976, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Homeowner1
Enabled: true
waypointsPool: 541
startWaypoint: 540
patrolSpeed: 0.75
chaseSpeed: 2
turningSpeed: 5
sightDistance: 8
eyeOffset: [0, 1.64999998, 0]
distanceToCapture: 0.800000012
captureTime: 0.5
footstepSFXIntervalMultiplier: 0.5
- EID: 541
Name: ====WaypointPool====
IsActive: true
@ -12335,7 +12290,7 @@
NumberOfChildren: 8
Components:
Transform Component:
Translate: {x: 5.5, y: 0.171148509, z: 10}
Translate: {x: 5.5, y: 0.300000012, z: 10}
Rotate: {x: -0, y: -3.1415925, z: 0}
Scale: {x: 0.999999404, y: 1, z: 0.999999404}
IsActive: true
@ -15498,3 +15453,125 @@
Acceleration: {x: 0, y: 0.100000001, z: 0}
IsActive: true
Scripts: ~
- EID: 66078
Name: ====AI=====
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.667429447, y: 0, z: 1.10868871}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 148542784
Material: 121518381
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.100000001
Gravity Scale: 1
Use Gravity: true
Interpolate: false
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: true
Freeze Rotation Y: false
Freeze Rotation Z: true
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 5
Type: Box
Half Extents: {x: 0.200000003, y: 1.79999995, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
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: SHADE_Scripting.Gameplay.AIBehaviour.AIRework.AILineOfSight
Enabled: true
player: 65775
range: 5
angle: 30
angleBetween: 0
distance: 0
heightLimit: 1
rayOffset: [0, 0, 0]
withinRange: false
withinSight: false
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: 541
patrolSpeed: 1
chaseSpeed: 3
alertCooldown: 0
player: 65775
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: 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.800000012, 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: 66078

View File

@ -127,14 +127,17 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
private void AICheat()
{
StateMachine machine = GetScript<StateMachine>();
if(machine)
AILineOfSight los = GetScript<AILineOfSight>();
if(machine && los)
{
if (Input.GetKeyDown(Input.KeyCode.F))
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

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static PlayerController;
@ -11,15 +12,25 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
public class HomeOwnerAttackHitbox : Script
{
public GameObject aiGO;
Transform transform;
Transform aiTransform;
protected override void start()
{
transform = GetComponent<Transform>();
aiTransform = aiGO.GetComponent<Transform>();
}
protected override void update()
{
Transform transform = GetComponent<Transform>();
Transform aiTransform = aiGO.GetComponent<Transform>();
if (transform)
if (transform && aiTransform)
{
transform.GlobalPosition = aiTransform.GlobalPosition;
transform.GlobalPosition = aiTransform.GlobalPosition + aiTransform.Forward * 0.7f;
transform.GlobalEulerAngles = aiTransform.GlobalEulerAngles;
}
}
@ -33,11 +44,15 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
pc.currentState = RaccoonStates.CAUGHT;
if (pc.stateMachine && !pc.stateMachine.IsState(typeof(PlayerCaughtState)))
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.stateMachine.SetState(typeof(PlayerCaughtState));
pc.GotCaught();
if (ai)
ai.Reset();
{
ai.Reset();
GameObject.SetActive(false);
}
}
}

View File

@ -14,12 +14,14 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
float windupTime = 8.0f / 30.0f;
float holdTime = 0.3f;
float seqTime = 8.0f / 30.0f + 0.5f;
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)
{
@ -34,6 +36,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
windUp = true;
hold = false;
seq = false;
end = false;
timer = windupTime;
RotateToVelocity rotate = machine.GetScript<RotateToVelocity>();
@ -45,8 +48,19 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
{
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);
}
@ -61,18 +75,7 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
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);
}
@ -103,12 +106,29 @@ namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States
}
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)
if (los && los.withinSight)
{
machine.SetState(typeof(ChaseState));
}

View File

@ -240,8 +240,8 @@ namespace SHADE
if (system->drawNavigationArea)
{
SHTransform trans;
trans.position = SHVec3{ 0.0f };
trans.scale = navigationAreaSize;
trans.position = system->origin_editor;
trans.scale = system->size_editor;
trans.ComputeTRS();
debugDrawSystem->DrawWireCube(trans.trs, SHColour::YELLOW, false);
}