Merge remote-tracking branch 'origin/main' into SP3-2-Physics

This commit is contained in:
Diren D Bharwani 2023-01-31 17:14:52 +08:00
commit 3b6e0be364
332 changed files with 17892 additions and 7203 deletions

4
.gitignore vendored
View File

@ -364,3 +364,7 @@ MigrationBackup/
*.filters *.filters
Assets/Editor/Layouts/UserLayout.ini Assets/Editor/Layouts/UserLayout.ini
JSON/Schemas/Catalog/
Assets/Editor/Editor.SHConfig

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 86098106 Starting Scene ID: 87244611
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

96
Assets/Bindings.SHConfig Normal file
View File

@ -0,0 +1,96 @@
7
Controller Look Horizontal
0
0
5
0.2
5
0
0
0
1
18
0
Controller Look Vertical
0
0
5
0.2
5
0
0
0
1
19
0
Horizontal
0
0
5
0.2
5
1
2
39
68
2
37
65
2
3
16
1
2
Jump
0
0
1000
0.2
1000
0
1
32
0
1
10
0
Mouse Look Horizontal
1
0
1
0.2
1
0
0
0
0
0
Mouse Look Vertical
2
0
1
0.2
1
0
0
0
0
0
Vertical
0
0
5
0.2
5
1
2
38
87
2
40
83
2
0
17
1
1

View File

@ -0,0 +1,4 @@
Start Maximized: true
Working Scene ID: 97402985
Window Size: {x: 1920, y: 1013}
Style: 0

View File

@ -0,0 +1,8 @@
- VertexShader: 47911992
FragmentShader: 46377769
SubPass: G-Buffer Write
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 58303057
data.alpha: 0
data.beta: {x: 1, y: 1, z: 1}

View File

@ -0,0 +1,3 @@
Name: AnimatedBag
ID: 117923942
Type: 7

View File

@ -0,0 +1,8 @@
- VertexShader: 47911992
FragmentShader: 46377769
SubPass: G-Buffer Write
Properties:
data.color: {x: 1, y: 1, z: 1, w: 1}
data.textureIndex: 64651793
data.alpha: 0
data.beta: {x: 1, y: 1, z: 1}

View File

@ -0,0 +1,3 @@
Name: AnimatedRaccoon
ID: 128805346
Type: 7

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,7 @@
Name: BoneIKTest4
ID: 81814706
Type: 4
Sub Assets:
Name: Cube
ID: 137599708
Type: 8

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,46 @@
Name: MD_BreakableObjects1
ID: 68661596
Type: 4
Sub Assets:
Name: Plate01_Unshattered
ID: 140964851
Type: 8
Name: Plate01_Shattered.004
ID: 136742160
Type: 8
Name: Plate01_Shattered.001
ID: 146557542
Type: 8
Name: Plate01_Shattered.002
ID: 145439064
Type: 8
Name: Plate01_Shattered.003
ID: 139411134
Type: 8
Name: Bowl01_Unshattered
ID: 144894491
Type: 8
Name: Bowl01_Shattered.001
ID: 140591337
Type: 8
Name: Bowl01_Shattered.002
ID: 148464002
Type: 8
Name: Bowl01_Shattered.003
ID: 144132426
Type: 8
Name: Cup01_Unshattered
ID: 134951952
Type: 8
Name: Cup01_Shattered.001
ID: 140710075
Type: 8
Name: Cup01_Shattered.002
ID: 147241586
Type: 8
Name: Cup01_Shattered.003
ID: 141067850
Type: 8
Name: Cup01_Shattered.004
ID: 142028102
Type: 8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,276 @@
- EID: 0
Name: Main Camera
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0.472120881, z: 2.53064919}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Camera Component:
Position: {x: 0, y: 0.472120881, z: 2.53064919}
Pitch: 0
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Scripts: ~
- EID: 2
Name: Light
IsActive: true
NumberOfChildren: 0
Components:
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 0
IsActive: true
Scripts: ~
- EID: 1
Name: Plate
IsActive: true
NumberOfChildren: 4
Components:
Transform Component:
Translate: {x: 0.00451920554, y: 0.829197884, z: 1.75}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 0.999979734, y: 1, z: 0.999979734}
IsActive: true
Renderable Component:
Mesh: 140964851
Material: 126974645
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.200000003, y: 0.100000001, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts:
- Type: Breakable
Enabled: true
threshHold: 0
force: 1
- EID: 4
Name: Piece1
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3.2922253e-07, y: 0, z: -0.0171992779}
Rotate: {x: -1.31316483e-07, y: 3.60887498e-09, z: 5.27542454e-11}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 146557542
Material: 124370424
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 5
Name: Piece2
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.47731805e-07, y: 0, z: 0.0325666666}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 145439064
Material: 124370424
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.200000003}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 6
Name: Piece3
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -0.0502781346, y: 1.18017197e-05, z: 6.97374344e-05}
Rotate: {x: 0.021297913, y: 0.00146768149, z: -5.48749846e-08}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 139411134
Material: 124370424
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 7
Name: Piece4
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0.0364143178, y: 7.39097595e-06, z: 6.61611557e-05}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 136742160
Material: 124370424
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.100000001, y: 0.0500000007, z: 0.150000006}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 3
Name: Ground
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -0.414889663, z: 0}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 5, y: 1, z: 5}
IsActive: true
RigidBody Component:
Type: Static
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~

View File

@ -0,0 +1,3 @@
Name: Breakables
ID: 85040588
Type: 5

File diff suppressed because it is too large Load Diff

View File

@ -8599,6 +8599,7 @@
Arm Length: 1 Arm Length: 1
Look At Camera Origin: true Look At Camera Origin: true
Target Offset: {x: 0, y: 0, z: 0} Target Offset: {x: 0, y: 0, z: 0}
Camera Collision: false
IsActive: true IsActive: true
Scripts: Scripts:
- Type: SHADE_Scripting.ThirdPersonCamera - Type: SHADE_Scripting.ThirdPersonCamera
@ -8640,7 +8641,7 @@
Components: Components:
Transform Component: Transform Component:
Translate: {x: 2.70000005, y: 0.100000001, z: -2} Translate: {x: 2.70000005, y: 0.100000001, z: -2}
Rotate: {x: -0, y: 0, z: -0} Rotate: {x: -0, y: -2.09439516, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
@ -8665,7 +8666,7 @@
Colliders: Colliders:
- Is Trigger: false - Is Trigger: false
Type: Box Type: Box
Half Extents: {x: 1, 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

View File

@ -7,6 +7,7 @@
Translate: {x: 0, y: 0.304069757, z: 1.73034382} Translate: {x: 0, y: 0.304069757, z: 1.73034382}
Rotate: {x: 0, y: 0, z: 0} Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true
Camera Component: Camera Component:
Position: {x: 0, y: 0.304069757, z: 1.73034382} Position: {x: 0, y: 0.304069757, z: 1.73034382}
Pitch: 0 Pitch: 0
@ -17,6 +18,7 @@
Near: 0.00999999978 Near: 0.00999999978
Far: 10000 Far: 10000
Perspective: true Perspective: true
IsActive: true
Scripts: ~ Scripts: ~
- EID: 1 - EID: 1
Name: Raccoon Name: Raccoon
@ -24,12 +26,14 @@
NumberOfChildren: 1 NumberOfChildren: 1
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 0, z: 0} Translate: {x: -1.86388135, y: 0.0544953719, z: 0}
Rotate: {x: 0, y: 0, z: 0} Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component: Renderable Component:
Mesh: 149697411 Mesh: 149697411
Material: 126974645 Material: 126974645
IsActive: true
Scripts: ~ Scripts: ~
- EID: 3 - EID: 3
Name: Bag Name: Bag
@ -40,9 +44,11 @@
Translate: {x: 0.006237939, y: -0.000393368304, z: 0} Translate: {x: 0.006237939, y: -0.000393368304, z: 0}
Rotate: {x: -0, y: 2.79945588, z: 0} Rotate: {x: -0, y: 2.79945588, z: 0}
Scale: {x: 1.0000881, y: 1, z: 1.0000881} Scale: {x: 1.0000881, y: 1, z: 1.0000881}
IsActive: true
Renderable Component: Renderable Component:
Mesh: 144838771 Mesh: 144838771
Material: 123745521 Material: 123745521
IsActive: true
Scripts: ~ Scripts: ~
- EID: 2 - EID: 2
Name: DirectionalLight Name: DirectionalLight
@ -50,12 +56,13 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Light Component: Light Component:
Position: {x: 0, y: 0, z: 0} Position: {x: 3, y: 4.5, z: 7}
Type: Directional Type: Directional
Direction: {x: 0, y: 0, z: 1} Direction: {x: -0.298000008, y: 0.522498012, z: 0.798600018}
Color: {x: 1, y: 1, z: 1, w: 1} Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295 Layer: 4294967295
Strength: 0 Strength: 0
IsActive: true
Scripts: ~ Scripts: ~
- EID: 4 - EID: 4
Name: AmbientLight Name: AmbientLight
@ -69,4 +76,20 @@
Color: {x: 1, y: 1, z: 1, w: 1} Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295 Layer: 4294967295
Strength: 0.600000024 Strength: 0.600000024
IsActive: true
Scripts: ~
- EID: 5
Name: Floor
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0.0810000002, z: 0}
Rotate: {x: -1.57079637, y: 0, z: 0}
Scale: {x: 50, y: 50, z: 50}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 124370424
IsActive: true
Scripts: ~ Scripts: ~

View File

@ -1,7 +1,7 @@
- EID: 0 - EID: 0
Name: Canvas Name: Canvas
IsActive: true IsActive: true
NumberOfChildren: 1 NumberOfChildren: 2
Components: Components:
Canvas Component: Canvas Component:
Canvas Width: 10 Canvas Width: 10
@ -28,6 +28,26 @@
Clicked Texture: 0 Clicked Texture: 0
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 5
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -3.9000001, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: true
Toggle Button Component:
Non Toggled Texture: 0
Toggled Texture: 0
Value: true
IsActive: true
Scripts: ~
- EID: 1 - EID: 1
Name: Camera Name: Camera
IsActive: true IsActive: true

View File

@ -1,3 +1,3 @@
Name: UI_Test Name: UI_Test
ID: 87707373 ID: 87244611
Type: 5 Type: 5

View File

@ -1,70 +0,0 @@
/*********************************************************************
* \file LeafAttack.cs
* \author Ryan Wang Nian Jing
* \brief Leaf node implementation for AI attacking the player
* when the AI is close enough after chasing
*
*
* \copyright Copyright (c) 2022 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//VARIABLES
public partial class LeafAttack : BehaviourTreeNode
{
//Holds the player game object
private GameObject player;
}
//FUNCTIONS
public partial class LeafAttack : BehaviourTreeNode
{
public LeafAttack(string name, GameObject p) : base (name)
{
player = p;
}
public override BehaviourTreeNodeStatus Evaluate()
{
//Debug.LogWarning("LeafAttack");
//Fail if no target in blackboard?
onEnter(BehaviourTreeNodeStatus.RUNNING);
//Succeed when stand in hurt box for long enough
object timeObj = GetNodeData("captureTimeLeft");
if (timeObj == null)
{
return BehaviourTreeNodeStatus.FAILURE;
}
float captureTime = (float)GetNodeData("captureTimeLeft");
captureTime -= Time.DeltaTimeF;
SetNodeData("captureTimeLeft", captureTime);
//Debug.Log(captureTime.ToString());
if (captureTime <= 0.0f)
{
//Catch player when in range for long enough
player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS);
return status;
}
//Return running if not success
//Debug.Log("Success: Caught");
status = BehaviourTreeNodeStatus.RUNNING;
onExit(BehaviourTreeNodeStatus.RUNNING);
return status;
}
}

View File

@ -1,183 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using SHADE;
public class AIPrototype : Script
{
//This object's relevant components
private Transform transform;
private RigidBody rb;
/*[SerializeField]
[Tooltip("The list of waypoints that the object will move around on")]
private Vector3[] waypoints;*/
private Vector3[] waypoints = { new Vector3(-8.0f, -2.0f, 3.5f), new Vector3(-8.0f, -2.0f, -13.0f), new Vector3(8.0f, -2.0f, -13.0f), new Vector3(8.0f, -2.0f, 3.5f) };
[SerializeField]
[Tooltip("How much force is applied in movement")]
private float movementForceMultiplier = 100.0f;
[SerializeField]
[Tooltip("How fast the object moves about waypoints")]
private float patrolSpeed = 0.4f;
[SerializeField]
[Tooltip("How fast the object moves while chasing")]
private float chaseSpeed = 0.8f;
[SerializeField]
[Tooltip("How near the player must be to the AI for capture")]
private float distanceToCapture = 1.2f;
[SerializeField]
[Tooltip("How near the player must be for the chase to begin. Should be less than distanceToEndChase")]
private float distanceToStartChase = 2.0f;
[SerializeField]
[Tooltip("How far the player must be for the chase to end. Should be greater than distanceToStartChase")]
private float distanceToEndChase = 2.5f;
//Whether the AI is chasing or not
private bool chaseMode;
//To cycle depending on the length of waypoints
private int currentTargetWaypointIndex;
private GameObject? player;
protected override void awake()
{
transform = GetComponent<Transform>();
if (transform == null)
{
Debug.LogError("Transform is NULL!");
}
rb = GetComponent<RigidBody>();
if (rb == null)
{
Debug.LogError("Rigidbody is NULL!");
}
currentTargetWaypointIndex = 0;
player = GameObject.Find("Player");
if (player == null)
{
Debug.LogError("Player is NULL!");
}
chaseMode = false;
}
protected override void fixedUpdate()
{
//Patrolling
if (!chaseMode)
{
//Head towards the next target
Vector3 normalisedDifference = waypoints[currentTargetWaypointIndex] - transform.GlobalPosition;
normalisedDifference /= normalisedDifference.GetMagnitude();
//transform.GlobalPosition += normalisedDifference * moveSpeed * (float)Time.DeltaTime;
//rb.LinearVelocity = normalisedDifference * patrolSpeed;
//ORIGINAL INTENDED CODE
/*rb.AddForce(new Vector3(normalisedDifference.x, 0.0f, normalisedDifference.z) * movementForceMultiplier);
float currentSpeed = MathF.Sqrt(rb.LinearVelocity.x * rb.LinearVelocity.x + rb.LinearVelocity.z * rb.LinearVelocity.z);
if (currentSpeed > patrolSpeed)
{
float adjustmentFactor = patrolSpeed / currentSpeed;
Vector3 adjustedVelocity = rb.LinearVelocity;
//adjustedVelocity *= adjustmentFactor;
adjustedVelocity.x = patrolSpeed;
adjustedVelocity.z = patrolSpeed;
rb.LinearVelocity = adjustedVelocity;
}*/
//TODO delete this when original intended code above works with velocity being limited correctly
rb.LinearVelocity = normalisedDifference * patrolSpeed;
//transform.GlobalRotation.SetLookRotation(waypoints[currentTargetWaypointIndex], Vector3.Up);
//Cycle to next waypoint if near enough current waypoint
if ((waypoints[currentTargetWaypointIndex] - transform.GlobalPosition).GetSqrMagnitude() <= 0.5f)
{
++currentTargetWaypointIndex;
if (currentTargetWaypointIndex >= waypoints.Length)
{
currentTargetWaypointIndex = 0; //Recycle
}
}
//Go chase if near enough to player
if (player != null)
{
Transform pTransform = player.GetValueOrDefault().GetComponent<Transform>();
if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() <= distanceToStartChase)
{
//Start the chase
chaseMode = true;
}
}
}
else //Chasing
{
if (player != null)
{
Transform pTransform = player.GetValueOrDefault().GetComponent<Transform>();
//Chase the player
Vector3 normalisedDifference = pTransform.GlobalPosition - transform.GlobalPosition;
normalisedDifference /= normalisedDifference.GetMagnitude();
//transform.GlobalPosition += normalisedDifference * moveSpeed * (float)Time.DeltaTime;
//ORIGINAL INTENDED CODE
/*rb.AddForce(new Vector3(normalisedDifference.x, 0.0f, normalisedDifference.z) * movementForceMultiplier);
float currentSpeed = MathF.Sqrt(rb.LinearVelocity.x * rb.LinearVelocity.x + rb.LinearVelocity.z * rb.LinearVelocity.z);
if (currentSpeed > chaseSpeed)
{
float adjustmentFactor = chaseSpeed / currentSpeed;
Vector3 adjustedVelocity = rb.LinearVelocity;
adjustedVelocity *= adjustmentFactor;
rb.LinearVelocity = adjustedVelocity;
}*/
//TODO delete this when original intended code above works with velocity being limited correctly
rb.LinearVelocity = normalisedDifference * chaseSpeed;
//Capture player if near enough
if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() <= distanceToCapture)
{
player.GetValueOrDefault().GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
}
//End chase if too far
if ((pTransform.GlobalPosition - transform.GlobalPosition).GetMagnitude() >= distanceToEndChase)
{
//Stop the chase
chaseMode = false;
//Find the nearest waypoint to go instead
float nearestWaypointDistance = 99999999999999.9f;
for (int i = 0; i < waypoints.Length; ++i)
{
if ((waypoints[i] - transform.GlobalPosition).GetSqrMagnitude() < nearestWaypointDistance)
{
nearestWaypointDistance = waypoints[i].GetSqrMagnitude();
currentTargetWaypointIndex = i;
}
}
}
}
}
}
}

View File

@ -1,3 +0,0 @@
Name: AIPrototype
ID: 163215061
Type: 9

View File

@ -66,9 +66,17 @@ namespace SHADE_Scripting.AIBehaviour.BehaviourTree
//Getters and setters for the blackboard //Getters and setters for the blackboard
public object GetData(string key) public object GetData(string key)
{ {
//Debug.Log("Getting Data " + key);
object outData = null; object outData = null;
if (blackboard.TryGetValue(key, out outData)) return outData; if (blackboard.TryGetValue(key, out outData))
else return outData; {
return outData;
}
else
{
//Debug.LogError("Cannot retrieve data " + key);
return outData;
}
} }
public void SetData(string key, object data) public void SetData(string key, object data)
{ {

View File

@ -84,17 +84,55 @@ public partial class Homeowner1 : BehaviourTree
_events = new Homeowner1Events(this); _events = new Homeowner1Events(this);
events.Initialise(); events.Initialise();
//Initialise the waypoints here //(25 Nov) DO NOT Initialise the data here
if (waypointsPool) /*if (waypointsPool)
{ {
waypoints = (List<GameObject>)waypointsPool.GetChildren(); waypoints = (List<GameObject>)waypointsPool.GetChildren();
SetData("waypoints", waypoints); SetData("waypoints", waypoints);
} }
SetData("transform", GetComponent<Transform>());
SetData("rigidBody", GetComponent<RigidBody>());
SetData("eyeOffset", eyeOffset);
SetData("sightDistance", sightDistance);
SetData("patrolSpeed", patrolSpeed);
SetData("chaseSpeed", chaseSpeed);
SetData("turningSpeed", turningSpeed);
SetData("distanceToCapture", distanceToCapture);
SetData("baseCaptureTime", captureTime);*/
} }
//Called every tick //Called every tick
protected override void Tick() protected override void Tick()
{ {
//Debug.Log("Ticking");
//Update data
if (GetData("waypoints") == null)
{
if (waypointsPool != GameObject.Null)
SetData("waypoints", (List<GameObject>)waypointsPool.GetChildren());
else
Debug.LogError("No waypoints, no AI");
}
if (GetData("transform") == null)
SetData("transform", GetComponent<Transform>());
if (GetData("rigidBody") == null)
SetData("rigidBody", GetComponent<RigidBody>());
if (GetData("eyeOffset") == null || (Vector3)GetData("eyeOffset") != eyeOffset)
SetData("eyeOffset", eyeOffset);
if (GetData("sightDistance") == null || (float)GetData("sightDistance") != sightDistance)
SetData("sightDistance", sightDistance);
if (GetData("patrolSpeed") == null || (float)GetData("patrolSpeed") != patrolSpeed)
SetData("patrolSpeed", patrolSpeed);
if (GetData("chaseSpeed") == null || (float)GetData("chaseSpeed") != chaseSpeed)
SetData("chaseSpeed", chaseSpeed);
if (GetData("turningSpeed") == null || (float)GetData("turningSpeed") != turningSpeed)
SetData("turningSpeed", turningSpeed);
if (GetData("distanceToCapture") == null || (float)GetData("distanceToCapture") != distanceToCapture)
SetData("distanceToCapture", distanceToCapture);
if (GetData("baseCaptureTime") == null || (float)GetData("baseCaptureTime") != captureTime)
SetData("baseCaptureTime", captureTime);
events.Tick(); events.Tick();
//Footsteps SFX, move them somewhere else soon //Footsteps SFX, move them somewhere else soon
@ -103,9 +141,10 @@ public partial class Homeowner1 : BehaviourTree
footstepTimeRemaining -= velocity * Time.DeltaTimeF; footstepTimeRemaining -= velocity * Time.DeltaTimeF;
if (footstepTimeRemaining < 0.0f) if (footstepTimeRemaining < 0.0f)
{ {
Debug.Log("AI Play Footstep SFX"); Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_footsteps");
footstepTimeRemaining = footstepSFXIntervalMultiplier; footstepTimeRemaining = footstepSFXIntervalMultiplier;
} }
//Debug.Log("Ticked");
} }
//Define the behaviour tree here //Define the behaviour tree here
@ -113,20 +152,22 @@ public partial class Homeowner1 : BehaviourTree
//The tree is called from the root every tick //The tree is called from the root every tick
protected override BehaviourTreeNode CreateTree() protected override BehaviourTreeNode CreateTree()
{ {
//Debug.Log("Creating Tree");
//Start from the root, structure it like this to make it look like a tree //Start from the root, structure it like this to make it look like a tree
BehaviourTreeNode root = new BehaviourTreeSelector("Root", new List<BehaviourTreeNode> BehaviourTreeNode root = new BehaviourTreeSelector("Root", new List<BehaviourTreeNode>
{ {
new BehaviourTreeSequence("Alerted", new List<BehaviourTreeNode> new BehaviourTreeSequence("Alerted", new List<BehaviourTreeNode>
{ {
new LeafSearch("SearchFOV", GetComponent<Transform>(), eyeOffset, sightDistance), new LeafSearch("SearchFOV"),
new BehaviourTreeSequence("CatchPlayer", new List<BehaviourTreeNode> new BehaviourTreeSequence("CatchPlayer", new List<BehaviourTreeNode>
{ {
new LeafChase("Chasing", GetComponent<Transform>(), GetComponent<RigidBody>(), chaseSpeed, turningSpeed, distanceToCapture, captureTime), new LeafChase("Chasing"),
new LeafAttack("Attacking", GameObject.Find("Player").GetValueOrDefault()) new LeafAttack("Attacking")
}) })
}), }),
new LeafPatrol("Patrol", GetComponent<Transform>(), patrolSpeed, turningSpeed, GetComponent<RigidBody>()) new LeafPatrol("Patrol")
}); });
//Debug.Log("Tree Created");
return root; return root;
} }
} }

View File

@ -0,0 +1,109 @@
/*********************************************************************
* \file LeafAttack.cs
* \author Ryan Wang Nian Jing
* \brief Leaf node implementation for AI attacking the player
* when the AI is close enough after chasing
*
*
* \copyright Copyright (c) 2022 DigiPen Institute of Technology. Reproduction
or disclosure of this file or its contents without the prior written
consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/
using SHADE;
using SHADE_Scripting.AIBehaviour.BehaviourTree;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//VARIABLES
public partial class LeafAttack : BehaviourTreeNode
{
//Holds the player game object that is to be targeted
private GameObject player;
}
//FUNCTIONS
public partial class LeafAttack : BehaviourTreeNode
{
public LeafAttack(string name) : base (name)
{
//Debug.Log("LeafAttack ctor");
}
//Helper, find the nearest unobstructed waypoint to return to when chase is over
public void reevaluateWaypoint()
{
List<GameObject> waypoints = (List<GameObject>)GetNodeData("waypoints");
Transform transform = (Transform)GetNodeData("transform");
if (waypoints == null || transform == null)
{
SetNodeData("currentWaypointIndex", 0);
return;
}
int nearestWaypointIndex = 0;
for (int i = 0; i < waypoints.Count; ++i)
{
if ((transform.GlobalPosition - waypoints[i].GetComponent<Transform>().GlobalPosition).GetSqrMagnitude() <
(transform.GlobalPosition - waypoints[nearestWaypointIndex].GetComponent<Transform>().GlobalPosition).GetSqrMagnitude())
{
nearestWaypointIndex = i;
}
}
SetNodeData("currentWaypointIndex", nearestWaypointIndex);
}
public override BehaviourTreeNodeStatus Evaluate()
{
//Debug.LogWarning("LeafAttack");
//Fail if no target in blackboard?
onEnter(BehaviourTreeNodeStatus.RUNNING);
//Get Data
float? captureTime;
if (GetNodeData("captureTimeLeft") == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
else
captureTime = (float)GetNodeData("captureTimeLeft");
if (GameObject.Find("Player") == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
else
player = GameObject.Find("Player").GetValueOrDefault();
//Succeed when stand in hurt box for long enough
//Debug.Log("Attempting to get blackboard data");
//Debug.Log("Got blackboard data");
captureTime -= Time.DeltaTimeF;
SetNodeData("captureTimeLeft", captureTime);
//Debug.Log(captureTime.ToString());
if (captureTime <= 0.0f)
{
//Catch player when in range for long enough
//Debug.Log("Success: Caught");
player.GetScript<PlayerController>().currentState = PlayerController.RaccoonStates.CAUGHT;
status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS);
return status;
}
//Return running if not success
//Debug.Log("Running: About to capture in " + captureTimeLeft);
status = BehaviourTreeNodeStatus.RUNNING;
onExit(BehaviourTreeNodeStatus.RUNNING);
return status;
}
}

View File

@ -24,9 +24,9 @@ public partial class LeafChase : BehaviourTreeNode
private Transform transform; private Transform transform;
private RigidBody rb; private RigidBody rb;
private float chaseSpeed; private float chaseSpeed;
private float turnSpeed; private float turningSpeed;
private float captureDistance; private float captureDistance;
private float captureTime; private float baseCaptureTime;
} }
//FUNCTIONS //FUNCTIONS
@ -34,29 +34,69 @@ public partial class LeafChase : BehaviourTreeNode
{ {
//Despite inheriting from BehaviourTreeNode, we don't have children to this node, //Despite inheriting from BehaviourTreeNode, we don't have children to this node,
//and hence we don't need to inherit its constructors //and hence we don't need to inherit its constructors
public LeafChase(string name, Transform t, RigidBody rb, float cSpd, float tSpd, float capDist, float capTime) : base (name) public LeafChase(string name) : base (name)
{ {
transform = t; //Debug.Log("LeafChase ctor");
this.rb = rb; }
chaseSpeed = cSpd;
turnSpeed = tSpd; //Helper, find which waypoint player is closest to
captureDistance = capDist; private void determinePlayerWaypoint()
captureTime = capTime; {
List<GameObject> waypoints = (List<GameObject>)GetNodeData("waypoints");
Transform target = (Transform)GetNodeData("target");
if (waypoints == null || target == null)
{
return;
}
int nearestWaypointIndex = 0;
for (int i = 0; i < waypoints.Count; ++i)
{
if ((target.GlobalPosition - waypoints[i].GetComponent<Transform>().GlobalPosition).GetSqrMagnitude() <
(target.GlobalPosition - waypoints[nearestWaypointIndex].GetComponent<Transform>().GlobalPosition).GetSqrMagnitude())
{
nearestWaypointIndex = i;
}
}
//Debug.Log("Player is nearest " + nearestWaypointIndex);
//Debug.Log("I'm at " + (int)GetNodeData("currentWaypointIndex"));
SetNodeData("playerLastSightedWaypointIndex", nearestWaypointIndex);
} }
public override BehaviourTreeNodeStatus Evaluate() public override BehaviourTreeNodeStatus Evaluate()
{ {
//Debug.LogWarning("LeafChase"); //Debug.LogWarning("LeafChase");
onEnter(BehaviourTreeNodeStatus.RUNNING);
//Get Data
if (GetNodeData("transform") == null ||
GetNodeData("rigidBody") == null ||
GetNodeData("turningSpeed") == null ||
GetNodeData("chaseSpeed") == null ||
GetNodeData("distanceToCapture") == null ||
GetNodeData("baseCaptureTime") == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
else
{
transform = (Transform)GetNodeData("transform");
rb = (RigidBody)GetNodeData("rigidBody");
chaseSpeed = (float)GetNodeData("chaseSpeed");
turningSpeed = (float)GetNodeData("turningSpeed");
captureDistance = (float)GetNodeData("distanceToCapture");
baseCaptureTime = (float)GetNodeData("baseCaptureTime");
}
//Fail if no target in blackboard //Fail if no target in blackboard
if (GetNodeData("target") == null) if (GetNodeData("target") == null)
{ {
//Debug.Log("Failure: No target in blackboard"); //Debug.Log("Failure: No target in blackboard");
return BehaviourTreeNodeStatus.FAILURE; return BehaviourTreeNodeStatus.FAILURE;
} }
onEnter(BehaviourTreeNodeStatus.RUNNING);
Transform target = (Transform)GetNodeData("target"); Transform target = (Transform)GetNodeData("target");
Vector3 normalisedDifference = target.GlobalPosition - transform.GlobalPosition; Vector3 normalisedDifference = target.GlobalPosition - transform.GlobalPosition;
@ -71,7 +111,7 @@ public partial class LeafChase : BehaviourTreeNode
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{ {
Debug.Log("AI play unalert hmm"); Audio.PlaySFXOnce2D("event:/Homeowner/humming");
} }
SetNodeData("isAlert", false); SetNodeData("isAlert", false);
@ -93,13 +133,32 @@ public partial class LeafChase : BehaviourTreeNode
{ {
//Debug.Log("Running: Chasing"); //Debug.Log("Running: Chasing");
Quaternion targetRotation = Quaternion.LookRotation(normalisedDifference, new Vector3(0.0f, 1.0f, 0.0f)); Quaternion targetRotation = Quaternion.LookRotation(normalisedDifference, new Vector3(0.0f, 1.0f, 0.0f));
transform.LocalRotation = Quaternion.Slerp(transform.LocalRotation, targetRotation, turnSpeed * Time.DeltaTimeF); transform.LocalRotation = Quaternion.Slerp(transform.LocalRotation, targetRotation, turningSpeed * Time.DeltaTimeF);
//Determine the player's nearest waypoint as long as the AI can see the player
//Head towards that waypoint in an attempt to chase the player
determinePlayerWaypoint();
//TODO delete this when original intendd code above works with velocity being limited correctly //TODO delete this when original intendd code above works with velocity being limited correctly
//Only chase the player directly if the player's waypoint matches the AI's own
if (GetNodeData("currentWaypointIndex") != null && GetNodeData("playerLastSightedWaypointIndex") != null)
{
if ((int)GetNodeData("currentWaypointIndex") == (int)GetNodeData("playerLastSightedWaypointIndex"))
{
//Debug.Log("Waypoint indicees matching. Chasing directly");
rb.LinearVelocity = normalisedDifference * chaseSpeed; rb.LinearVelocity = normalisedDifference * chaseSpeed;
}
else
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return BehaviourTreeNodeStatus.FAILURE;
}
}
//Reset capture timing to base //Reset capture timing to base
SetNodeData("captureTimeLeft", captureTime); SetNodeData("captureTimeLeft", baseCaptureTime);
//Not capturing, don't play SFX //Not capturing, don't play SFX
SetNodeData("isCapturing", false); SetNodeData("isCapturing", false);
@ -114,12 +173,12 @@ public partial class LeafChase : BehaviourTreeNode
//Debug.Log("Success: Near enough. Begin attack"); //Debug.Log("Success: Near enough. Begin attack");
//Look at the correct direction //Look at the correct direction
Quaternion targetRotation = Quaternion.LookRotation(normalisedDifference, new Vector3(0.0f, 1.0f, 0.0f)); Quaternion targetRotation = Quaternion.LookRotation(normalisedDifference, new Vector3(0.0f, 1.0f, 0.0f));
transform.LocalRotation = Quaternion.Slerp(transform.LocalRotation, targetRotation, turnSpeed * Time.DeltaTimeF); transform.LocalRotation = Quaternion.Slerp(transform.LocalRotation, targetRotation, turningSpeed * Time.DeltaTimeF);
//Play SFX //Play SFX
if (GetNodeData("isCapturing") != null && (bool)GetNodeData("isCapturing") == false) if (GetNodeData("isCapturing") != null && (bool)GetNodeData("isCapturing") == false)
{ {
Debug.Log("AI Play capturing SFX"); //Debug.Log("AI Play capturing SFX");
} }
SetNodeData("isCapturing", true); SetNodeData("isCapturing", true);

View File

@ -22,13 +22,15 @@ public partial class LeafPatrol : BehaviourTreeNode
{ {
//Waypoints and movement //Waypoints and movement
private Transform transform; private Transform transform;
private List<GameObject> waypoints; private List<GameObject>? waypoints;
private RigidBody rb; private RigidBody rb;
private float patrolSpeed; private float patrolSpeed;
private float chaseSpeed;
private float turningSpeed; private float turningSpeed;
private float retreatTimer = 0.0f; private float retreatTimer = 0.0f;
private int currentWaypointIndex = 0; private int currentWaypointIndex = 0;
private bool retreatState = false; private bool retreatState = false;
private bool goingForwards = true;
//Small delays between waypoints //Small delays between waypoints
private bool isWaiting = false; private bool isWaiting = false;
@ -42,13 +44,8 @@ public partial class LeafPatrol : BehaviourTreeNode
//Constructor, establish values here //Constructor, establish values here
//Despite inheriting from BehaviourTreeNode, we don't have children to this //Despite inheriting from BehaviourTreeNode, we don't have children to this
//node, and hence we do not need to inherit its constructors //node, and hence we do not need to inherit its constructors
public LeafPatrol(string name, Transform t, float patrolSpeed, float turnSpeed, RigidBody rb) : base(name) public LeafPatrol(string name) : base(name)
{ {
transform = t;
this.patrolSpeed = patrolSpeed;
turningSpeed = turnSpeed;
this.rb = rb;
currentWaypointIndex = 0; currentWaypointIndex = 0;
} }
@ -58,6 +55,27 @@ public partial class LeafPatrol : BehaviourTreeNode
{ {
//Debug.LogWarning("LeafPatrol"); //Debug.LogWarning("LeafPatrol");
onEnter(BehaviourTreeNodeStatus.RUNNING); onEnter(BehaviourTreeNodeStatus.RUNNING);
//Get data
if (GetNodeData("transform") == null ||
GetNodeData("patrolSpeed") == null ||
GetNodeData("chaseSpeed") == null ||
GetNodeData("turningSpeed") == null ||
GetNodeData("rigidBody") == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
else
{
transform = (Transform)GetNodeData("transform");
patrolSpeed = (float)GetNodeData("patrolSpeed");
chaseSpeed = (float)GetNodeData("chaseSpeed");
turningSpeed = (float)GetNodeData("turningSpeed");
rb = (RigidBody)GetNodeData("rigidBody");
}
if (GetNodeData("currentWaypointIndex") == null) if (GetNodeData("currentWaypointIndex") == null)
{ {
SetNodeData("currentWaypointIndex", 0); SetNodeData("currentWaypointIndex", 0);
@ -77,38 +95,90 @@ public partial class LeafPatrol : BehaviourTreeNode
//Waiting, do not move //Waiting, do not move
if (GetNodeData("isWaiting") != null) if (GetNodeData("isWaiting") != null)
{ {
//Only wait to change waypoints if not alert
if (GetNodeData("isAlert") != null && !(bool)GetNodeData("isAlert"))
waitCounter = 0.0f; waitCounter = 0.0f;
isWaiting = true; isWaiting = true;
ClearNodeData("isWaiting"); ClearNodeData("isWaiting");
return; return;
} }
waypoints = (List<GameObject>)GetNodeData("waypoints");
object waypoint = GetNodeData("waypoints"); if (waypoints == null)
if (waypoint == null)
{ {
return; return;
} }
waypoints = (List<GameObject>)waypoint;
Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent<Transform>().GlobalPosition; Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent<Transform>().GlobalPosition;
//Reach waypoint by X and Z being near enough //Reach waypoint by X and Z being near enough
//Do not consider Y of waypoints yet //Do not consider Y of waypoints yet
Vector3 remainingDistance = targetPosition - transform.GlobalPosition; Vector3 remainingDistance = targetPosition - transform.GlobalPosition;
remainingDistance.y = 0.0f; remainingDistance.y = 0.0f;
//Reached waypoint, cycle //Reached waypoint, cycle
if (remainingDistance.GetSqrMagnitude() < 0.1f) if (remainingDistance.GetSqrMagnitude() < 0.1f)
{ {
//If alert, may reverse
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert"))
{
//If alert, may reverse if it's closer to the player
if (GetNodeData("playerLastSightedWaypointIndex") != null)
{
int playerWaypoint = (int)GetNodeData("playerLastSightedWaypointIndex");
int forwardDistance = 0;
int backDistance = 0;
if (playerWaypoint < currentWaypointIndex)
{
//Player waypoint is behind current waypoint
forwardDistance = playerWaypoint + waypoints.Count() - currentWaypointIndex;
backDistance = currentWaypointIndex - playerWaypoint;
}
else
{
//Player waypoint is ahead of current waypoint (or same)
forwardDistance = playerWaypoint - currentWaypointIndex;
backDistance = currentWaypointIndex + waypoints.Count() - playerWaypoint;
}
if (backDistance < forwardDistance)
{
//Go backwards
goingForwards = false;
}
else
{
//Go forward
goingForwards = true;
}
}
else
{
//Fallback if no player waypoint data, go forward
goingForwards = true;
}
}
//Cycle waypoints //Cycle waypoints
if (goingForwards)
{
++currentWaypointIndex; ++currentWaypointIndex;
if (currentWaypointIndex >= waypoints.Count()) if (currentWaypointIndex >= waypoints.Count())
currentWaypointIndex = 0; currentWaypointIndex = 0;
}
else
{
--currentWaypointIndex;
if (currentWaypointIndex < 0)
currentWaypointIndex = waypoints.Count() - 1;
}
//Write to blackboard //Write to blackboard
SetNodeData("currentWaypointIndex", currentWaypointIndex); SetNodeData("currentWaypointIndex", currentWaypointIndex);
//Only wait to change waypoints if not alert
if (GetNodeData("isAlert") != null && !(bool)GetNodeData("isAlert"))
waitCounter = 0.0f; waitCounter = 0.0f;
isWaiting = true; isWaiting = true;
} }
else if (false /*Physics.OverlapSphere(_selfTransform.position, 0.3f, 1 << 8).Length > 0 && retreatState == false*/) else if (false /*Physics.OverlapSphere(_selfTransform.position, 0.3f, 1 << 8).Length > 0 && retreatState == false*/)
@ -150,9 +220,33 @@ public partial class LeafPatrol : BehaviourTreeNode
//TODO delete this when original intended code above works with velocity being limited correctly //TODO delete this when original intended code above works with velocity being limited correctly
if (rb != null) if (rb != null)
{ {
//Debug.Log("Null check passed?"); //Move quickly if alert
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert"))
{
//Debug.Log("Fast Patrol");
rb.LinearVelocity = normalisedDifference * chaseSpeed;
}
else
{
rb.LinearVelocity = normalisedDifference * patrolSpeed; rb.LinearVelocity = normalisedDifference * patrolSpeed;
} }
//Unalert if AI reaches player nearest
if (GetNodeData("currentWaypointIndex") != null && GetNodeData("playerLastSightedWaypointIndex") != null)
{
if ((int)GetNodeData("currentWaypointIndex") == (int)GetNodeData("playerLastSightedWaypointIndex"))
{
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert"))
{
//Debug.Log("Unalert");
Audio.PlaySFXOnce2D("event:/Homeowner/humming");
Audio.StopAllSounds();
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
}
SetNodeData("isAlert", false);
}
}
}
if (retreatState) if (retreatState)
{ {
if (retreatTimer < 1.0f) retreatTimer += Time.DeltaTimeF; if (retreatTimer < 1.0f) retreatTimer += Time.DeltaTimeF;
@ -167,7 +261,6 @@ public partial class LeafPatrol : BehaviourTreeNode
private void DelayAtWaypoint() private void DelayAtWaypoint()
{ {
//Debug.Log("DelayAtWaypoint");
waitCounter += Time.DeltaTimeF; waitCounter += Time.DeltaTimeF;
if (waitCounter >= waitDuration) if (waitCounter >= waitDuration)
isWaiting = false; isWaiting = false;

View File

@ -30,18 +30,14 @@ public partial class LeafSearch : BehaviourTreeNode
//FUNCTIONS HERE //FUNCTIONS HERE
public partial class LeafSearch : BehaviourTreeNode public partial class LeafSearch : BehaviourTreeNode
{ {
public LeafSearch(string name, Transform t, Vector3 eo, float sDist) : base(name) public LeafSearch(string name) : base(name)
{ {
transform = t; //Debug.Log("LeafSearch ctor");
eyeOffset = eo;
sightDistance = sDist;
player = null;
} }
//Helper, find the nearest unobstructed waypoint to return to when chase is over //Helper, find the nearest unobstructed waypoint to return to when chase is over
private void reevaluateWaypoint() public void reevaluateWaypoint()
{ {
Debug.Log("Reevaluating Waypoints");
List<GameObject> waypoints = (List<GameObject>)GetNodeData("waypoints"); List<GameObject> waypoints = (List<GameObject>)GetNodeData("waypoints");
if (waypoints == null) if (waypoints == null)
@ -62,11 +58,40 @@ public partial class LeafSearch : BehaviourTreeNode
SetNodeData("currentWaypointIndex", nearestWaypointIndex); SetNodeData("currentWaypointIndex", nearestWaypointIndex);
} }
//Helper for handling being alert
//Helper for handling stopping of chases
private void handleChaseStop()
{
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true)
{
Audio.PlaySFXOnce2D("event:/Homeowner/humming");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
}
public override BehaviourTreeNodeStatus Evaluate() public override BehaviourTreeNodeStatus Evaluate()
{ {
//Debug.LogWarning("LeafSearch"); //Debug.LogWarning("LeafSearch");
onEnter(BehaviourTreeNodeStatus.RUNNING); onEnter(BehaviourTreeNodeStatus.RUNNING);
//Get data
if (GetNodeData("transform") == null ||
GetNodeData("eyeOffset") == null ||
GetNodeData("sightDistance") == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
else
{
transform = (Transform)GetNodeData("transform");
eyeOffset = (Vector3)GetNodeData("eyeOffset");
sightDistance = (float)GetNodeData("sightDistance");
}
//Search for player //Search for player
player = GameObject.Find("Player"); player = GameObject.Find("Player");
@ -94,12 +119,7 @@ public partial class LeafSearch : BehaviourTreeNode
if ((plrT.GlobalPosition - transform.GlobalPosition).GetMagnitude() > sightDistance) if ((plrT.GlobalPosition - transform.GlobalPosition).GetMagnitude() > sightDistance)
{ {
//Debug.Log("Failure: Too far"); //Debug.Log("Failure: Too far");
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) //handleChaseStop();
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
status = BehaviourTreeNodeStatus.FAILURE; status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE); onExit(BehaviourTreeNodeStatus.FAILURE);
return status; return status;
@ -114,12 +134,7 @@ public partial class LeafSearch : BehaviourTreeNode
if (Vector3.Dot(difference, lookDirection) < 0.0f) if (Vector3.Dot(difference, lookDirection) < 0.0f)
{ {
//Debug.Log("Failure: Out of FOV"); //Debug.Log("Failure: Out of FOV");
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) //handleChaseStop();
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
status = BehaviourTreeNodeStatus.FAILURE; status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE); onExit(BehaviourTreeNodeStatus.FAILURE);
return status; return status;
@ -132,20 +147,27 @@ public partial class LeafSearch : BehaviourTreeNode
//Draw a ray, succeed if ray is unobstructed //Draw a ray, succeed if ray is unobstructed
Vector3 eyePosition = transform.GlobalPosition + eyeOffset; Vector3 eyePosition = transform.GlobalPosition + eyeOffset;
Ray sightRay = new Ray(eyePosition, plrT.GlobalPosition - eyePosition); BoxCollider playerCollider = player.GetValueOrDefault().GetComponent<Collider>().GetCollisionShape<BoxCollider>(0);
if (playerCollider == null)
{
//Debug.Log("Failure: Player has no collider");
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
//Ray destination to target the centre of the player's collider instead of transform position
//Since transform position is often the raccoon's base and the ray needs to hit somewhere higher to be more reliable
Vector3 rayDestination = plrT.GlobalPosition + plrT.GlobalScale * playerCollider.PositionOffset;
Ray sightRay = new Ray(eyePosition, rayDestination - eyePosition);
RaycastHit sightRayHit = Physics.Raycast(sightRay); RaycastHit sightRayHit = Physics.Raycast(sightRay);
//As of November 2022, RaycastHit contains only the FIRST object hit by //As of November 2022, RaycastHit contains only the FIRST object hit by
//the ray in the Other GameObject data member //the ray in the Other GameObject data member
//Diren may likely add ALL objects hit by the ray over December //Diren may likely add ALL objects hit by the ray over December
if (sightRayHit.Hit && sightRayHit.Other != player) if (sightRayHit.Hit && sightRayHit.Other != player)
{ {
//TODO sometimes the ray doesn't hit the player even if he's in plain sight because the ray hits the floor the player is on instead???
//Debug.Log("Failure: Ray hit obstacle named " + sightRayHit.Other.GetValueOrDefault().Name + " ID" + sightRayHit.Other.GetValueOrDefault().EntityId); //Debug.Log("Failure: Ray hit obstacle named " + sightRayHit.Other.GetValueOrDefault().Name + " ID" + sightRayHit.Other.GetValueOrDefault().EntityId);
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == true) //handleChaseStop();
{
Debug.Log("AI play unalert hmm");
reevaluateWaypoint();
}
SetNodeData("isAlert", false);
status = BehaviourTreeNodeStatus.FAILURE; status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE); onExit(BehaviourTreeNodeStatus.FAILURE);
return status; return status;
@ -160,11 +182,25 @@ public partial class LeafSearch : BehaviourTreeNode
//Write player's transform into the blackboard //Write player's transform into the blackboard
SetNodeData("target", plrT); SetNodeData("target", plrT);
if (GetNodeData("isAlert") == null)
{
SetNodeData("isAlert", true);
Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon");
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected");
Audio.StopAllSounds();
Audio.PlayBGMOnce2D("event:/Music/player_detected");
}
else
{
if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false) if (GetNodeData("isAlert") != null && (bool)GetNodeData("isAlert") == false)
{ {
Debug.Log("AI Play Alerted Yell here"); Audio.PlaySFXOnce2D("event:/Homeowner/homeowner_detect_raccoon");
Audio.PlaySFXOnce2D("event:/Music/stingers/player_detected");
Audio.StopAllSounds();
Audio.PlayBGMOnce2D("event:/Music/player_detected");
} }
SetNodeData("isAlert", true); SetNodeData("isAlert", true);
}
status = BehaviourTreeNodeStatus.SUCCESS; status = BehaviourTreeNodeStatus.SUCCESS;
onExit(BehaviourTreeNodeStatus.SUCCESS); onExit(BehaviourTreeNodeStatus.SUCCESS);

View File

@ -0,0 +1,65 @@
using SHADE;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
public class Breakable : Script
{
public float threshHold = 1.0f;
public float force = 2.0f;
private RigidBody rb;
private Transform trans;
private bool isBreak = false;
private List<GameObject> itemPieces = new List<GameObject>();
private Random ran = new Random();
protected override void awake()
{
rb = GetComponent<RigidBody>();
if (!rb)
Debug.LogError("RIGIDBODY EMPTY");
trans = GetComponent<Transform>();
if(!trans)
Debug.LogError("TRANSFORM EMPTY");
foreach (GameObject pieces in GameObject)
{
itemPieces.Add(pieces);
pieces.SetActive(false);
}
}
protected override void update()
{
if (isBreak)
Break();
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (rb.LinearVelocity.GetSqrMagnitude() > threshHold)
{
isBreak = true;
}
}
protected override void onTriggerEnter(CollisionInfo info)
{
}
private void Break()
{
foreach (GameObject item in itemPieces)
{
item.SetActive(true);
item.GetComponent<Transform>().GlobalPosition = trans.LocalPosition + item.GetComponent<Transform>().LocalPosition;
GameObject gO = item;
gO.Parent = GameObject.Null;
}
isBreak = false;
Audio.PlaySFXOnce2D("event:/Props/impact_break");
Owner.SetActive(false);
}
}

View File

@ -0,0 +1,3 @@
Name: SC_Breakable
ID: 161935110
Type: 9

View File

@ -18,12 +18,10 @@ public class Item : Script
protected override void awake() protected override void awake()
{ {
rb = GetComponent<RigidBody>(); rb = GetComponent<RigidBody>();
if (rb)
{
rb.FreezeRotationX = false;
rb.FreezeRotationY = false;
rb.FreezeRotationZ = false;
} }
protected override void update()
{
} }
protected override void onCollisionEnter(CollisionInfo info) protected override void onCollisionEnter(CollisionInfo info)

View File

@ -7,85 +7,80 @@ using static Item;
public class PickAndThrow : Script public class PickAndThrow : Script
{ {
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f); public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
public Vector3 cameraArmOffSet = new Vector3(0.0f, 0.25f, 0.0f);
public GameObject item { get; set; } public GameObject item { get; set; }
public float delayTimer = 1.0f; public float delayTimer = 1.0f;
public float aimingLength = 1.5f; public float aimingLength = 1.5f;
private float timer; private float timer;
private PlayerController pc; private PlayerController pc;
private Camera cam;
private Transform itemTransform; private Transform itemTransform;
private RigidBody itemRidibody; private RigidBody itemRidigBody;
private Transform raccoonHoldLocation; private Collider itemCollider;
private Transform playerTran;
private Item itemScript; private Item itemScript;
private Transform raccoonHoldLocation;
private ThirdPersonCamera tpc; private ThirdPersonCamera tpc;
private float lastXDir; private float lastXDir;
private float lastZDir; private float lastZDir;
private bool inRange = false; private bool inRange = false;
public bool throwItem = false;
[Tooltip("Lenght of ray")]
public float rayDistance = 1;
protected override void awake() protected override void awake()
{ {
playerTran = GetComponent<Transform>();
if (!playerTran)
Debug.Log("PLAYERTRANSFORM EMPTY"); ;
pc = GetScript<PlayerController>(); pc = GetScript<PlayerController>();
if(!pc) if(!pc)
Debug.Log("PLAYER CONTROLLER EMPTY"); Debug.LogError("PLAYER CONTROLLER EMPTY");
raccoonHoldLocation = GetComponentInChildren<Transform>(); raccoonHoldLocation = GetComponentInChildren<Transform>();
if (!raccoonHoldLocation) if (!raccoonHoldLocation)
Debug.Log("CHILD EMPTY"); Debug.LogError("CHILD EMPTY");
tpc = GetScriptInChildren<ThirdPersonCamera>(); tpc = GetScriptInChildren<ThirdPersonCamera>();
if(!tpc) if(!tpc)
Debug.Log("TPC EMPTY"); Debug.LogError("TPC EMPTY");
timer = delayTimer; timer = delayTimer;
} }
protected override void update() protected override void update()
{ {
if(timer <= delayTimer) if(timer <= delayTimer)
timer += Time.DeltaTimeF; timer += Time.DeltaTimeF;
CalculateDir(); CalculateDir();
CastRay();
if (pc && itemRidibody && itemTransform) if (pc && itemRidigBody && itemTransform && itemCollider)
{ {
if (pc.holdItem) if (pc.holdItem)
{ {
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition; itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
itemTransform.LocalRotation = playerTran.LocalRotation; itemTransform.LocalRotation = pc.tranform.LocalRotation;
itemRidigBody.LinearVelocity = Vector3.Zero;
itemRidigBody.AngularVelocity = Vector3.Zero;
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
{ {
pc.isAiming = true; pc.isAiming = true;
pc.camArm.ArmLength = aimingLength; pc.camArm.ArmLength = aimingLength;
pc.camArm.TargetOffset = cameraArmOffSet;
} }
if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming)
{ {
Audio.PlaySFXOnce2D("event:/Raccoon/raccoon_throw"); Audio.PlaySFXOnce2D("event:/Raccoon/raccoon_throw");
itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false;
pc.isAiming = false; pc.isAiming = false;
pc.camArm.TargetOffset = Vector3.Zero;
if (tpc) if (tpc)
pc.camArm.ArmLength = tpc.armLength; pc.camArm.ArmLength = tpc.armLength;
pc.holdItem = false; pc.holdItem = false;
inRange = false; inRange = false;
itemRidibody.IsGravityEnabled = true; throwItem = true;
if (itemScript)
{
Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir);
if (itemScript.currCategory == ItemCategory.LIGHT)
itemRidibody.AddForce(vec * 0.3f);
if (itemScript.currCategory == ItemCategory.MEDIUM)
itemRidibody.AddForce(vec * 0.75f);
if (itemScript.currCategory == ItemCategory.HEAVY)
itemRidibody.AddForce(vec);
}
itemRidibody.LinearVelocity += pc.rb.LinearVelocity;
ResetItemObject();
timer = 0.0f; timer = 0.0f;
} }
@ -93,20 +88,25 @@ public class PickAndThrow : Script
{ {
pc.holdItem = false; pc.holdItem = false;
inRange = false; inRange = false;
itemRidibody.IsGravityEnabled = true; itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false;
ResetItemObject(); ResetItemObject();
} }
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && pc.isAiming) if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && pc.isAiming)
{ {
pc.isAiming = false; pc.isAiming = false;
pc.camArm.TargetOffset = Vector3.Zero;
if (tpc) if (tpc)
pc.camArm.ArmLength = tpc.armLength; pc.camArm.ArmLength = tpc.armLength;
} }
} }
else if (!pc.holdItem) else if (!pc.holdItem)
itemRidibody.IsGravityEnabled = true; {
itemRidigBody.IsGravityEnabled = true;
itemCollider.GetCollisionShape(0).IsTrigger = false;
}
} }
if (timer > delayTimer && pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) if (timer > delayTimer && pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
@ -119,10 +119,31 @@ public class PickAndThrow : Script
} }
} }
protected override void fixedUpdate()
{
if (throwItem && itemRidigBody && pc)
{
if (itemScript)
{
Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir);
if (itemScript.currCategory == ItemCategory.LIGHT)
itemRidigBody.AddForce(vec * 0.2f);
if (itemScript.currCategory == ItemCategory.MEDIUM)
itemRidigBody.AddForce(vec * 0.75f);
if (itemScript.currCategory == ItemCategory.HEAVY)
itemRidigBody.AddForce(vec);
}
itemRidigBody.LinearVelocity += pc.rb.LinearVelocity;
throwItem = false;
ResetItemObject();
}
}
private void ResetItemObject() private void ResetItemObject()
{ {
itemRidibody = null; itemRidigBody = null;
itemTransform = null; itemTransform = null;
itemCollider = null;
itemScript = null; itemScript = null;
item = new GameObject(); item = new GameObject();
} }
@ -130,40 +151,43 @@ public class PickAndThrow : Script
private void RetrieveItemComponets() private void RetrieveItemComponets()
{ {
//get the transform of the given item //get the transform of the given item
if (item.GetScript<Item>() && itemTransform == null && itemRidibody == null) if (item.GetScript<Item>() && !itemTransform && !itemRidigBody)
{ {
itemRidibody = item.GetComponent<RigidBody>(); itemRidigBody = item.GetComponent<RigidBody>();
if (itemRidibody == null) if (!itemRidigBody)
Debug.Log("Item rb EMPTY"); Debug.Log("Item rb EMPTY");
else else
{ {
itemRidibody.IsGravityEnabled = false; itemRidigBody.IsGravityEnabled = false;
itemRidibody.LinearVelocity = Vector3.Zero;
itemRidibody.AngularVelocity = Vector3.Zero;
} }
itemTransform = item.GetComponent<Transform>(); itemTransform = item.GetComponent<Transform>();
if (itemTransform == null) if (!itemTransform)
Debug.Log("Item transform EMPTY"); Debug.Log("Item transform EMPTY");
else else
{ {
itemTransform.LocalEulerAngles = Vector3.Zero; itemTransform.LocalEulerAngles = Vector3.Zero;
} }
itemCollider = item.GetComponent<Collider>();
if (!itemCollider)
Debug.Log("Item collider EMPTY");
else
{
itemCollider.GetCollisionShape(0).IsTrigger = true;
}
itemScript = item.GetScript<Item>(); itemScript = item.GetScript<Item>();
if(!itemScript) if(!itemScript)
Debug.Log("Item script EMPTY"); Debug.Log("Item script EMPTY");
} }
} }
private void CalculateDir() private void CalculateDir()
{ {
if (cam == null) if (pc && pc.cam)
cam = GetComponentInChildren<Camera>();
else if (cam)
{ {
Vector3 camerAixs = cam.GetForward(); Vector3 camerAixs = pc.cam.GetForward();
camerAixs.y = 0; camerAixs.y = 0;
camerAixs.Normalise(); camerAixs.Normalise();
lastXDir = camerAixs.x; lastXDir = camerAixs.x;
@ -171,33 +195,36 @@ public class PickAndThrow : Script
} }
} }
private void DelayCheck() private void CastRay()
{ {
timer += Time.DeltaTimeF; if (pc != null)
}
protected override void onCollisionEnter(CollisionInfo info)
{ {
} Vector3 dirNor = pc.tranform.Forward;
protected override void onTriggerEnter(CollisionInfo info) Vector3 playerRayPos = pc.tranform.GlobalPosition;
{ playerRayPos.y += 0.05f;
if (info.GameObject.GetScript<Item>() && !pc.holdItem) dirNor.Normalise();
{ RaycastHit ray1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance);
item = info.GameObject; RaycastHit ray2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance);
inRange = true; RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f);
} inRange = CheckForItem(ray1) || CheckForItem(ray2) || CheckForItem(ray3);
}
protected override void onTriggerStay(CollisionInfo info)
{
//Debug.Log("STAY");
}
protected override void onTriggerExit(CollisionInfo info)
{
//Debug.Log("EXIT");
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
{
inRange = false;
} }
} }
private bool CheckForItem(RaycastHit ray)
{
if (ray.Hit)
{
if (ray.Other.Value.GetScript<Item>() && !pc.holdItem)
{
item = ray.Other.Value;
return true;
}
else
return false;
}
return false;
}
} }

View File

@ -27,8 +27,8 @@ public class PlayerController : Script
}*/ }*/
public RigidBody rb { get; set; } public RigidBody rb { get; set; }
private Transform tranform; public Transform tranform { get; set; }
private Camera cam; public Camera cam { get; set; }
public CameraArm camArm { get; set; } public CameraArm camArm { get; set; }
private PickAndThrow pat; private PickAndThrow pat;
private StateMachine stateMachine; private StateMachine stateMachine;
@ -119,7 +119,6 @@ public class PlayerController : Script
protected override void lateUpdate() protected override void lateUpdate()
{ {
//rb.FreezePositionY = false;
} }
protected override void update() protected override void update()
{ {
@ -152,6 +151,7 @@ public class PlayerController : Script
camArm = GetComponentInChildren<CameraArm>(); camArm = GetComponentInChildren<CameraArm>();
Rotation(); Rotation();
Jump();
GotCaught(); GotCaught();
//Debug.Log($"{currentState}"); //Debug.Log($"{currentState}");
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}"); //Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
@ -165,7 +165,6 @@ public class PlayerController : Script
MoveKey(); MoveKey();
Move(); Move();
Sprint(); Sprint();
Jump();
Gravity(); Gravity();
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}"); //Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
} }

View File

@ -15,6 +15,8 @@ namespace SHADE_Scripting
public float turnSpeedPitch = 0.3f; public float turnSpeedPitch = 0.3f;
public float turnSpeedYaw = 0.5f; public float turnSpeedYaw = 0.5f;
public float pitchClamp = 45.0f; public float pitchClamp = 45.0f;
public bool inverseXControls = false;
public bool inverseYControls = false;
protected override void awake() protected override void awake()
{ {
@ -42,7 +44,14 @@ namespace SHADE_Scripting
if (arm) if (arm)
{ {
Vector2 vel = Input.GetMouseVelocity(); Vector2 vel = Input.GetMouseVelocity();
if(inverseYControls)
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
else
arm.Pitch += vel.y * turnSpeedPitch * Time.DeltaTimeF;
if (inverseXControls)
arm.Yaw -= vel.x * turnSpeedYaw * Time.DeltaTimeF;
else
arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF; arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF;
if (arm.Pitch > pitchClamp) if (arm.Pitch > pitchClamp)

View File

@ -0,0 +1,3 @@
Name: SC_ThirdPersonCamera
ID: 166247489
Type: 9

View File

@ -1,3 +0,0 @@
Name: ThirdPersonCamera
ID: 154161201
Type: 9

View File

@ -38,21 +38,17 @@ public class GameManager : Script
protected override void awake() protected override void awake()
{ {
Audio.PlayBGMOnce2D("event:/Music/player_undetected"); Audio.PlayBGMOnce2D("event:/Music/player_undetected");
Audio.PlayBGMOnce2D("event:/Ambience/roomtone_kitchen");
totalItemCount = 0; totalItemCount = 0;
Score = 0; Score = 0;
currGameState = GameState.START; currGameState = GameState.START;
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
} }
protected override void update() protected override void update()
{ {
Cheats();
if (once) if (once)
{ {
if (itemPool) if (itemPool)
@ -62,6 +58,14 @@ public class GameManager : Script
foreach (Item i in listOfItems) foreach (Item i in listOfItems)
totalItemCount += 1; totalItemCount += 1;
} }
if (zonePool)
{
listOfZone = zonePool.GetScriptsInChildren<ScoringZone>();
if (listOfZone != null)
foreach (ScoringZone sz in listOfZone)
sz.gameManger = Owner.GetScript<GameManager>();
}
once = false; once = false;
} }
@ -73,17 +77,30 @@ public class GameManager : Script
if(timeText) if(timeText)
timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}"; timeText.GetComponent<TextRenderable>().Text = $"Time Left: {timer.ToString("0.00")}";
if (timer > 0 && totalItemCount <= 0) if ((timer > 0 && totalItemCount <= 0) || Input.GetKeyDown(Input.KeyCode.F1))
{ {
currGameState = GameState.WIN; currGameState = GameState.WIN;
Audio.StopAllSounds();
SceneManager.ChangeScene(winScene); SceneManager.ChangeScene(winScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_win");
} }
else if(timer < 0) else if(timer < 0 || Input.GetKeyDown(Input.KeyCode.F2))
{ {
currGameState = GameState.LOSE; currGameState = GameState.LOSE;
Audio.StopAllSounds();
SceneManager.ChangeScene(loseScene); SceneManager.ChangeScene(loseScene);
Audio.PlaySFXOnce2D("event:/Music/stingers/game_lose");
} }
} }
} }
private void Cheats()
{
if (Input.GetKeyDown(Input.KeyCode.Escape))
{
Audio.StopAllSounds();
SceneManager.ChangeScene(97158628);
}
}
} }

View File

@ -4,6 +4,7 @@ using System;
public class SoundsBoard : Script public class SoundsBoard : Script
{ {
AudioClipHandler test;
protected override void awake() protected override void awake()
{ {
/* /*
@ -31,13 +32,21 @@ event:/Homeowner/homeowner_humming
event:/Homeowner/homeowner_footsteps event:/Homeowner/homeowner_footsteps
event:/Homeowner/homeowner_detect_raccoon event:/Homeowner/homeowner_detect_raccoon
*/ */
test = Audio.CreateAudioClip("event:/Music/player_undetected");
Audio.AddAudioClipToSFXChannelGroup(test);
}
protected override void start()
{
test.Play();
} }
protected override void update() protected override void update()
{ {
if (Input.GetKeyDown(Input.KeyCode.Q)) if (Input.GetKeyDown(Input.KeyCode.Q))
Audio.PlayBGMOnce2D("event:/UI/mouse_down_element"); test.Play();
if (Input.GetKeyDown(Input.KeyCode.W)) if (Input.GetKeyDown(Input.KeyCode.W))
Audio.PlayBGMOnce2D("event:/UI/mouse_down_empty"); test.Stop(true);
if (Input.GetKeyDown(Input.KeyCode.E)) if (Input.GetKeyDown(Input.KeyCode.E))
Audio.PlayBGMOnce2D("event:/UI/mouse_enter_element"); Audio.PlayBGMOnce2D("event:/UI/mouse_enter_element");
if (Input.GetKeyDown(Input.KeyCode.R)) if (Input.GetKeyDown(Input.KeyCode.R))

View File

@ -11,15 +11,25 @@ public class EndScene : Script
} }
protected override void update() protected override void update()
{ {
if (Input.GetKey(Input.KeyCode.R)) if (Input.GetKeyDown(Input.KeyCode.R))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
}
if (Input.GetKeyUp(Input.KeyCode.R))
{
Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds();
SceneManager.ChangeScene(mainGameScene); SceneManager.ChangeScene(mainGameScene);
} }
if (Input.GetKey(Input.KeyCode.M)) if (Input.GetKeyDown(Input.KeyCode.M))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
}
if (Input.GetKeyUp(Input.KeyCode.M))
{
Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds();
SceneManager.ChangeScene(mainMainScene); SceneManager.ChangeScene(mainMainScene);
} }

View File

@ -9,14 +9,19 @@ public class MainMenu : Script
} }
protected override void update() protected override void update()
{ {
if (Input.GetKey(Input.KeyCode.Space)) if (Input.GetKeyDown(Input.KeyCode.Space))
{ {
Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); Audio.PlaySFXOnce2D("event:/UI/mouse_down_element");
SceneManager.ChangeScene(89830755); }
if (Input.GetKeyUp(Input.KeyCode.Space))
{
Audio.PlaySFXOnce2D("event:/UI/success");
SceneManager.ChangeScene(86098106);
Audio.StopAllSounds(); Audio.StopAllSounds();
} }
if (Input.GetKey(Input.KeyCode.Escape)) if (Input.GetKeyDown(Input.KeyCode.Escape))
{ {
Audio.StopAllSounds(); Audio.StopAllSounds();
Application.Quit(); Application.Quit();

View File

@ -0,0 +1,78 @@
#version 450
#extension GL_KHR_vulkan_glsl : enable
//#include "ShaderDescriptorDefinitions.glsl"
layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec3 aNormal;
layout(location = 3) in vec3 aTangent;
layout(location = 4) in mat4 worldTransform;
layout(location = 8) in uvec2 integerData;
layout(location = 9) in uvec4 aBoneIndices;
layout(location = 10) in vec4 aBoneWeights;
layout(location = 11) in uint firstBoneIndex;
layout(location = 0) out struct
{
vec4 vertPos; // location 0
vec2 uv; // location = 1
vec4 normal; // location = 2
vec4 worldPos; // location = 3
} Out;
// material stuff
layout(location = 4) out struct
{
int materialIndex;
uint eid;
uint lightLayerIndex;
} Out2;
layout(set = 1, binding = 0) uniform CameraData
{
vec4 position;
mat4 vpMat;
mat4 viewMat;
mat4 projMat;
} cameraData;
layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices
{
mat4 data[];
} BoneMatrices;
void main()
{
Out2.materialIndex = gl_InstanceIndex;
Out2.eid = integerData[0];
Out2.lightLayerIndex = integerData[1];
// for transforming gBuffer position and normal data
mat4 modelViewMat = cameraData.viewMat * worldTransform;
// gBuffer position will be in view space
Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f);
Out.worldPos = worldTransform * vec4 (aVertexPos, 1.0f);
// uvs for texturing in fragment shader
Out.uv = aUV;
mat3 transposeInv = mat3 (transpose(inverse(modelViewMat)));
// normals are also in view space
Out.normal.rgb = transposeInv * aNormal.rgb;
Out.normal.rgb = normalize (Out.normal.rgb);
// Compute bone matrix
mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0];
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1];
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2];
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3];
// clip space for rendering
gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f);
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Anim_VS
ID: 47911992
Type: 2

View File

@ -0,0 +1,26 @@
#version 450
#extension GL_KHR_vulkan_glsl : enable
layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in mat4 worldTransform;
layout(location = 5) in vec4 color;
// Output
layout(location = 0) out struct
{
vec4 Color;
} Out;
layout(set = 1, binding = 0) uniform CameraData
{
vec4 position;
mat4 vpMat;
mat4 viewMat;
mat4 projMat;
} cameraData;
void main()
{
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos.xyz, 1.0f);
Out.Color = color;
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: DebugDrawMesh_VS
ID: 42127043
Type: 2

Some files were not shown because too many files have changed in this diff Show More