From c07fa3c5ae59400a3784a67c6fbaa3d76baf1753 Mon Sep 17 00:00:00 2001 From: Glence Date: Fri, 25 Nov 2022 00:54:45 +0800 Subject: [PATCH] remove the clamp from the phsysicSystem routines added cheats for maingame added raycast for pick throw --- Assets/Scenes/MainGame.shade | 97 ++----------------- .../Gameplay/Player/SC_PickAndThrow.cs | 63 +++++------- Assets/Scripts/Gameplay/SC_GameManager.cs | 33 +++++-- Assets/Scripts/SC_MainMenu.cs | 4 +- .../System/SHPhysicsSystemRoutines.cpp | 1 - 5 files changed, 62 insertions(+), 136 deletions(-) diff --git a/Assets/Scenes/MainGame.shade b/Assets/Scenes/MainGame.shade index 16de4ea8..7b0fa57d 100644 --- a/Assets/Scenes/MainGame.shade +++ b/Assets/Scenes/MainGame.shade @@ -8236,15 +8236,7 @@ Colliders: - Is Trigger: false Type: Box - Half Extents: {x: 0.200000003, y: 0.200000003, 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} - - Is Trigger: true - Type: Box - Half Extents: {x: 0.400000006, y: 0.400000006, z: 0.400000006} + Half Extents: {x: 0.100000001, y: 0.100000001, z: 0.100000001} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -8288,15 +8280,7 @@ Colliders: - Is Trigger: false Type: Box - Half Extents: {x: 0.5, y: 0.150000006, z: 0.5} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Rotation Offset: {x: 0, y: 0, z: 0} - - Is Trigger: true - Type: Box - Half Extents: {x: 0.699999988, y: 0.300000012, z: 0.75} + Half Extents: {x: 0.25, y: 0.075000003, z: 0.25} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -8340,15 +8324,7 @@ Colliders: - Is Trigger: false Type: Box - Half Extents: {x: 0.300000012, y: 0.300000012, z: 0.300000012} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Rotation Offset: {x: 0, y: 0, z: 0} - - Is Trigger: true - Type: Box - Half Extents: {x: 0.5, y: 0.5, z: 0.5} + Half Extents: {x: 0.150000006, y: 0.150000006, z: 0.150000006} Friction: 0.400000006 Bounciness: 0 Density: 1 @@ -8558,10 +8534,12 @@ heavyMultiper: 0.25 - Type: PickAndThrow Enabled: true - throwForce: [50, 50, 50] + throwForce: [8, 10, 8] + item: 51000 delayTimer: 1 aimingLength: 0.5 - rayDistance: 1 + inRange: false + rayDistance: 0.5 - EID: 3 Name: HoldingPoint IsActive: true @@ -8633,63 +8611,4 @@ Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true - Scripts: ~ -- EID: 196 - Name: ====AI===== - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 2.70000005, y: 0.100000001, z: -2} - Rotate: {x: -0, y: 0, z: -0} - Scale: {x: 1, y: 1, z: 1} - IsActive: true - Renderable Component: - Mesh: 140697366 - Material: 129495479 - IsActive: true - RigidBody Component: - Type: Dynamic - Drag: 0.00999999978 - Angular Drag: 0.00999999978 - 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 - Type: Box - Half Extents: {x: 1, 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 - player: 2 - waypoints: - - [2.70000005, 0, -2] - - [-0.300000012, 0, -2.70000005] - - [-2, 0, -3.79999995] - - [-4, 0, -2.0999999] - - [-2.9000001, 0, 2.4000001] - - [-1, 0, 4] - - [2.70000005, 0, 4] - patrolSpeed: 1 - chaseSpeed: 2 - turningSpeed: 5 - sightDistance: 8 - eyeOffset: [0, 0, 0] - distanceToCapture: 0.5 - captureTime: 0.5 - footstepSFXIntervalMultiplier: 0.5 \ No newline at end of file + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs index 27243029..af9ebc5e 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs @@ -7,7 +7,7 @@ using static Item; public class PickAndThrow : Script { public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f); - public GameObject item { get; set; } + public GameObject item; public float delayTimer = 1.0f; public float aimingLength = 1.5f; @@ -17,18 +17,16 @@ public class PickAndThrow : Script private Transform itemTransform; private RigidBody itemRidibody; private Transform raccoonHoldLocation; - private Transform playerTran; private Item itemScript; private ThirdPersonCamera tpc; private float lastXDir; private float lastZDir; - private bool inRange = false; + public bool inRange = false; private Collider collider; - private BoxCollider cs; [Tooltip("Lenght of ray")] - public float rayDistance = 3; + public float rayDistance = 1; protected override void awake() { @@ -49,7 +47,6 @@ public class PickAndThrow : Script Debug.LogError("COLLIDER EMPTY"); else { - cs = collider.GetCollisionShape(0); } timer = delayTimer; @@ -60,13 +57,14 @@ public class PickAndThrow : Script timer += Time.DeltaTimeF; CalculateDir(); + CastRay(); if (pc && itemRidibody && itemTransform) { if (pc.holdItem) { itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition; - itemTransform.LocalRotation = playerTran.LocalRotation; + itemTransform.LocalRotation = pc.tranform.LocalRotation; if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) { @@ -86,6 +84,7 @@ public class PickAndThrow : Script if (itemScript) { Vector3 vec = new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir); + //to be change if (itemScript.currCategory == ItemCategory.LIGHT) itemRidibody.AddForce(vec * 0.3f); if (itemScript.currCategory == ItemCategory.MEDIUM) @@ -130,7 +129,6 @@ public class PickAndThrow : Script protected override void fixedUpdate() { - CastRay(); } private void ResetItemObject() @@ -144,7 +142,7 @@ public class PickAndThrow : Script private void RetrieveItemComponets() { //get the transform of the given item - if (item.GetScript() && itemTransform == null && itemRidibody == null) + if (item.GetScript() && !itemTransform && !itemRidibody ) { itemRidibody = item.GetComponent(); if (itemRidibody == null) @@ -187,43 +185,34 @@ public class PickAndThrow : Script private void CastRay() { - if (pc != null && cs != null) + if (pc != null) { Vector3 dirNor = pc.tranform.Forward; - //change when cs.HalfExtents.z works - //cs.HalfExtents.z - Vector3 playerRayPos = pc.tranform.GlobalPosition + (dirNor * (0.3f + 0.1f)); - playerRayPos.y += 0.1f; + Vector3 playerRayPos = pc.tranform.GlobalPosition; + playerRayPos.y += 0.05f; dirNor.Normalise(); RaycastHit ray1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance); RaycastHit ray2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance); - RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.5f); + RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f); + inRange = CheckForItem(ray1) || CheckForItem(ray2) || CheckForItem(ray3); } } + private bool CheckForItem(RaycastHit ray) + { + if (ray.Hit) + { + if (ray.Other.Value.GetScript() && !pc.holdItem) + { + item = ray.Other.Value; + return true; + } + else + return false; + } + return false; - protected override void onCollisionEnter(CollisionInfo info) - { - } - protected override void onTriggerEnter(CollisionInfo info) - { - if (info.GameObject.GetScript() && !pc.holdItem) - { - item = info.GameObject; - inRange = true; - } - } - protected override void onTriggerStay(CollisionInfo info) - { - //Debug.Log("STAY"); - } - protected override void onTriggerExit(CollisionInfo info) - { - //Debug.Log("EXIT"); - if (info.GameObject.GetScript() != null && !pc.holdItem) - { - inRange = false; - } } + } \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/SC_GameManager.cs b/Assets/Scripts/Gameplay/SC_GameManager.cs index b21bee42..ae98a54e 100644 --- a/Assets/Scripts/Gameplay/SC_GameManager.cs +++ b/Assets/Scripts/Gameplay/SC_GameManager.cs @@ -42,17 +42,12 @@ public class GameManager : Script Score = 0; currGameState = GameState.START; - if (zonePool) - { - listOfZone = zonePool.GetScriptsInChildren(); - if (listOfZone != null) - foreach (ScoringZone sz in listOfZone) - sz.gameManger = Owner.GetScript(); - } } protected override void update() { + Cheats(); + if (once) { if (itemPool) @@ -62,6 +57,14 @@ public class GameManager : Script foreach (Item i in listOfItems) totalItemCount += 1; } + + if (zonePool) + { + listOfZone = zonePool.GetScriptsInChildren(); + if (listOfZone != null) + foreach (ScoringZone sz in listOfZone) + sz.gameManger = Owner.GetScript(); + } once = false; } @@ -86,4 +89,20 @@ public class GameManager : Script } } + private void Cheats() + { + if (Input.GetKeyDown(Input.KeyCode.F1)) + { + SceneManager.ChangeScene(loseScene); + } + if (Input.GetKeyDown(Input.KeyCode.F2)) + { + SceneManager.ChangeScene(winScene); + } + if (Input.GetKeyDown(Input.KeyCode.Escape)) + { + SceneManager.ChangeScene(97158628); + } + } + } diff --git a/Assets/Scripts/SC_MainMenu.cs b/Assets/Scripts/SC_MainMenu.cs index 0cc5d0dd..cd2caf3f 100644 --- a/Assets/Scripts/SC_MainMenu.cs +++ b/Assets/Scripts/SC_MainMenu.cs @@ -9,14 +9,14 @@ public class MainMenu : Script } protected override void update() { - if (Input.GetKey(Input.KeyCode.Space)) + if (Input.GetKeyDown(Input.KeyCode.Space)) { Audio.PlaySFXOnce2D("event:/UI/mouse_down_element"); SceneManager.ChangeScene(86098106); Audio.StopAllSounds(); } - if (Input.GetKey(Input.KeyCode.Escape)) + if (Input.GetKeyDown(Input.KeyCode.Escape)) { Audio.StopAllSounds(); Application.Quit(); diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index 6168d673..6ab17077 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -144,7 +144,6 @@ namespace SHADE // HACK: Clamp DT here to prevent a ridiculous amount of updates. This limits updates from large dt to 2. // HACK: This should be done by the FRC and not here for predictable behaviour. - dt = std::clamp(dt, 0.0, 1.0 / 30.0); accumulatedTime += dt; //testFunction();