From 638286b35715a60a0d7f2df92bb455a5f8748b66 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 4 Feb 2023 01:57:27 +0800 Subject: [PATCH 1/3] Fixed missing trigger state --- .../System/Routines/SHPhysicsPostUpdateRoutine.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Physics/System/Routines/SHPhysicsPostUpdateRoutine.cpp b/SHADE_Engine/src/Physics/System/Routines/SHPhysicsPostUpdateRoutine.cpp index 5f97daaf..740df811 100644 --- a/SHADE_Engine/src/Physics/System/Routines/SHPhysicsPostUpdateRoutine.cpp +++ b/SHADE_Engine/src/Physics/System/Routines/SHPhysicsPostUpdateRoutine.cpp @@ -105,16 +105,14 @@ namespace SHADE * TODO: Test if the scene graph transforms abides by setting world position. Collisions will ignore the scene graph hierarchy. */ } - - // Since this function never runs when editor in not in play, execute the function anyway - physicsSystem->collisionListener.CleanContainers(); } - - // Collision & Trigger messages if (scriptingSystem != nullptr) scriptingSystem->ExecuteCollisionFunctions(); + + // Since this function never runs when editor in not in play, execute the function anyway + physicsSystem->collisionListener.CleanContainers(); } } // namespace SHADE \ No newline at end of file -- 2.40.1 From 7cf5ef4b812ffa20470d1beb3b2d6a0e0402d105 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 4 Feb 2023 14:21:40 +0800 Subject: [PATCH 2/3] Solved merge conflicts from main --- Assets/Scenes/PhysicsTest.shade | 31 +++++++- Assets/Scripts/Tests/PhysicsTestObj.cs | 11 ++- Assets/Scripts/Tests/TriggerTest.cs | 33 ++++++++ Assets/Scripts/Tests/TriggerTest.cs.shmeta | 3 + SHADE_Managed/src/Physics/CollisionTags.hxx | 85 +++++++++++++++++++++ 5 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 Assets/Scripts/Tests/TriggerTest.cs create mode 100644 Assets/Scripts/Tests/TriggerTest.cs.shmeta create mode 100644 SHADE_Managed/src/Physics/CollisionTags.hxx diff --git a/Assets/Scenes/PhysicsTest.shade b/Assets/Scenes/PhysicsTest.shade index 0b8b971f..1362a6a1 100644 --- a/Assets/Scenes/PhysicsTest.shade +++ b/Assets/Scenes/PhysicsTest.shade @@ -1,5 +1,5 @@ - EID: 0 - Name: Default + Name: Player IsActive: true NumberOfChildren: 0 Components: @@ -25,7 +25,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 2 + Collision Tag: 0 Type: Box Half Extents: {x: 1, y: 1, z: 1} Friction: 0.400000006 @@ -52,7 +52,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 5 + Collision Tag: 0 Type: Box Half Extents: {x: 1, y: 1, z: 1} Friction: 0.400000006 @@ -161,7 +161,7 @@ Collider Component: Colliders: - Is Trigger: false - Collision Tag: 7 + Collision Tag: 2 Type: Box Half Extents: {x: 1, y: 1, z: 1} Friction: 0.400000006 @@ -207,4 +207,27 @@ Position Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} IsActive: true + Scripts: ~ +- EID: 8 + Name: Target + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 8, y: 7, z: 0} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Collider Component: + Colliders: + - Is Trigger: false + Collision Tag: 0 + 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: ~ \ No newline at end of file diff --git a/Assets/Scripts/Tests/PhysicsTestObj.cs b/Assets/Scripts/Tests/PhysicsTestObj.cs index 7ea7f774..dbed19ef 100644 --- a/Assets/Scripts/Tests/PhysicsTestObj.cs +++ b/Assets/Scripts/Tests/PhysicsTestObj.cs @@ -6,6 +6,7 @@ using static Item; public class PhysicsTestObj : Script { + public Transform tf { get; set; } public RigidBody body { get; set; } public Collider collider { get; set; } @@ -68,6 +69,7 @@ public class PhysicsTestObj : Script protected override void awake() { + tf = GetComponent(); body = GetComponent(); collider = GetComponent(); @@ -80,9 +82,12 @@ public class PhysicsTestObj : Script protected override void update() { - Ray colliderRay = new Ray(); - colliderRay.Direction = Vector3.Right; - Physics.ColliderRaycast(collider.Owner, colliderRay, false, (ushort)64); + GameObject? target = GameObject.Find("Target"); + if (target.HasValue) + { + Physics.ColliderLineCast(collider.Owner, Vector3.Zero, target.Value.GetComponent().GlobalPosition, false, (ushort)64); + } + for (int i = 0; i < 6; ++i) { diff --git a/Assets/Scripts/Tests/TriggerTest.cs b/Assets/Scripts/Tests/TriggerTest.cs new file mode 100644 index 00000000..58352377 --- /dev/null +++ b/Assets/Scripts/Tests/TriggerTest.cs @@ -0,0 +1,33 @@ +using SHADE; +using System; +using System.Collections.Generic; +using static Item; + + +public class TriggerTest : Script +{ + public Collider collider { get; set; } + + protected override void awake() + { + collider = GetComponent(); + } + + protected override void onTriggerEnter(CollisionInfo info) + { + base.onTriggerEnter(info); + Debug.Log("Trigger Enter"); + } + + protected override void onTriggerStay(CollisionInfo info) + { + base.onTriggerStay(info); + Debug.Log("Trigger Stay"); + } + + protected override void onTriggerExit(CollisionInfo info) + { + base.onTriggerExit(info); + Debug.Log("Trigger Exit"); + } +}; diff --git a/Assets/Scripts/Tests/TriggerTest.cs.shmeta b/Assets/Scripts/Tests/TriggerTest.cs.shmeta new file mode 100644 index 00000000..99395db9 --- /dev/null +++ b/Assets/Scripts/Tests/TriggerTest.cs.shmeta @@ -0,0 +1,3 @@ +Name: TriggerTest +ID: 159344038 +Type: 9 diff --git a/SHADE_Managed/src/Physics/CollisionTags.hxx b/SHADE_Managed/src/Physics/CollisionTags.hxx new file mode 100644 index 00000000..90b6d854 --- /dev/null +++ b/SHADE_Managed/src/Physics/CollisionTags.hxx @@ -0,0 +1,85 @@ +/**************************************************************************************** + * \file CollisionTags.hxx + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for the managed Collision Tag Matrix & Collision Tag classes. + * + * \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. +****************************************************************************************/ + +#pragma once + +// Project Includes +#include "Math/Ray.hxx" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + /// + /// Represents a collision tag. + /// + public ref struct CollisionTag sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Name of the object that this Entity represents. + /// + property System::String^ Name + { + System::String^ get(); + void set(System::String^ value); + } + property unsigned short Mask + { + unsigned short get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Property Functions */ + /*-----------------------------------------------------------------------------*/ + + /// + /// Checks the state of a layer on the mask. + /// + /// The layer to check. + /// True if the state is active. + bool GetLayerState (int layer); + + /// + /// Sets the state of a layer on the mask. + /// + /// The layer to set. + /// The state of the layer to set. + void SetLayerState (int layer, bool state); + }; + + public ref class CollisionTagMatrix abstract sealed + { + public: + /*---------------------------------------------------------------------------------*/ + /* Member Functions */ + /*---------------------------------------------------------------------------------*/ + + /// + /// Get the name of a Collision Tag + /// + /// + /// The index of the tag in the matrix. + /// + /// The name of the collision tag. + System::String^ GetTagName(int tagIndex); + + + int GetTagIndex(System::String^ tagName); + + + }; + +} \ No newline at end of file -- 2.40.1 From c0249531d3d76018004ff3e56bb05c307f778826 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sat, 4 Feb 2023 15:18:15 +0800 Subject: [PATCH 3/3] Potential fix to physics collision states being incorrect --- Assets/Scenes/PhysicsTest.shade | 6 ++- Assets/Scripts/Tests/CollisionTest.cs | 45 +++++++++++++++++++ Assets/Scripts/Tests/CollisionTest.cs.shmeta | 3 ++ .../Routines/SHPhysicsDebugDrawRoutine.cpp | 12 ++++- .../src/Physics/System/SHPhysicsSystem.cpp | 1 + 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 Assets/Scripts/Tests/CollisionTest.cs create mode 100644 Assets/Scripts/Tests/CollisionTest.cs.shmeta diff --git a/Assets/Scenes/PhysicsTest.shade b/Assets/Scenes/PhysicsTest.shade index 1362a6a1..20903809 100644 --- a/Assets/Scenes/PhysicsTest.shade +++ b/Assets/Scenes/PhysicsTest.shade @@ -5,14 +5,14 @@ Components: Transform Component: Translate: {x: 0, y: 7, z: 0} - Rotate: {x: 0, y: 0, z: 0} + Rotate: {x: 1.48352981, y: 0, z: 0} Scale: {x: 0.999999344, y: 0.999999821, z: 0.999999523} IsActive: true RigidBody Component: Type: Dynamic Drag: 0.00999999978 Angular Drag: 0.100000001 - Use Gravity: false + Use Gravity: true Interpolate: false Sleeping Enabled: true Freeze Position X: false @@ -39,6 +39,8 @@ Enabled: true forceAmount: 50 torqueAmount: 500 + - Type: CollisionTest + Enabled: true - EID: 1 Name: Default IsActive: true diff --git a/Assets/Scripts/Tests/CollisionTest.cs b/Assets/Scripts/Tests/CollisionTest.cs new file mode 100644 index 00000000..869a94c1 --- /dev/null +++ b/Assets/Scripts/Tests/CollisionTest.cs @@ -0,0 +1,45 @@ +using SHADE; +using System; +using System.Collections.Generic; +using static Item; + + +public class CollisionTest : Script +{ + public Collider collider { get; set; } + + private bool printStay = false; + + protected override void awake() + { + collider = GetComponent(); + } + + protected override void onCollisionEnter(CollisionInfo info) + { + base.onCollisionEnter(info); + Debug.Log("Collision Enter"); + + printStay = false; + } + + protected override void onCollisionStay(CollisionInfo info) + { + base.onCollisionStay(info); + + if (!printStay) + { + Debug.Log("Collision Stay"); + printStay= true; + } + + } + + protected override void onCollisionExit(CollisionInfo info) + { + base.onCollisionExit(info); + Debug.Log("Collision Exit"); + + printStay = false; + } +}; diff --git a/Assets/Scripts/Tests/CollisionTest.cs.shmeta b/Assets/Scripts/Tests/CollisionTest.cs.shmeta new file mode 100644 index 00000000..46a0a155 --- /dev/null +++ b/Assets/Scripts/Tests/CollisionTest.cs.shmeta @@ -0,0 +1,3 @@ +Name: CollisionTest +ID: 163810535 +Type: 9 diff --git a/SHADE_Engine/src/Physics/System/Routines/SHPhysicsDebugDrawRoutine.cpp b/SHADE_Engine/src/Physics/System/Routines/SHPhysicsDebugDrawRoutine.cpp index 0d61a494..c73ccd11 100644 --- a/SHADE_Engine/src/Physics/System/Routines/SHPhysicsDebugDrawRoutine.cpp +++ b/SHADE_Engine/src/Physics/System/Routines/SHPhysicsDebugDrawRoutine.cpp @@ -18,6 +18,7 @@ #include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h" #include "Math/Transform/SHTransformComponent.h" #include "Physics/System/SHPhysicsSystem.h" +#include "Scene/SHSceneManager.h" #include "Tools/Utilities/SHUtilities.h" namespace SHADE @@ -53,12 +54,19 @@ namespace SHADE { const auto& COLLIDER_COMPONENT_DENSE = SHComponentManager::GetDense(); for (const auto& COLLIDER_COMPONENT : COLLIDER_COMPONENT_DENSE) - drawCollider(debugDrawSystem, COLLIDER_COMPONENT); + { + if (SHSceneManager::CheckNodeAndComponentsActive(COLLIDER_COMPONENT.GetEID())) + drawCollider(debugDrawSystem, COLLIDER_COMPONENT); + } } else if (!physicsDebugDrawSystem->collidersToDraw.empty()) { for (const auto EID : physicsDebugDrawSystem->collidersToDraw) - drawCollider(debugDrawSystem, *SHComponentManager::GetComponent(EID)); + { + if (SHSceneManager::CheckNodeAndHasComponentsActive(EID)) + drawCollider(debugDrawSystem, *SHComponentManager::GetComponent(EID)); + } + } auto* physicsSystem = SHSystemManager::GetSystem(); diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index f4529a40..5468147a 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -239,6 +239,7 @@ namespace SHADE // Unlink with managers objectManager.SetPhysicsWorld(nullptr); + collisionListener.ClearContainers(); return onSceneExitEvent.get()->handle; } -- 2.40.1