Potential fix to physics collision states being incorrect

This commit is contained in:
Diren D Bharwani 2023-02-04 15:18:15 +08:00
parent 7cf5ef4b81
commit c0249531d3
5 changed files with 63 additions and 4 deletions

View File

@ -5,14 +5,14 @@
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 7, z: 0} 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} Scale: {x: 0.999999344, y: 0.999999821, z: 0.999999523}
IsActive: true IsActive: true
RigidBody Component: RigidBody Component:
Type: Dynamic Type: Dynamic
Drag: 0.00999999978 Drag: 0.00999999978
Angular Drag: 0.100000001 Angular Drag: 0.100000001
Use Gravity: false Use Gravity: true
Interpolate: false Interpolate: false
Sleeping Enabled: true Sleeping Enabled: true
Freeze Position X: false Freeze Position X: false
@ -39,6 +39,8 @@
Enabled: true Enabled: true
forceAmount: 50 forceAmount: 50
torqueAmount: 500 torqueAmount: 500
- Type: CollisionTest
Enabled: true
- EID: 1 - EID: 1
Name: Default Name: Default
IsActive: true IsActive: true

View File

@ -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<Collider>();
}
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;
}
};

View File

@ -0,0 +1,3 @@
Name: CollisionTest
ID: 163810535
Type: 9

View File

@ -18,6 +18,7 @@
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h" #include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Physics/System/SHPhysicsSystem.h" #include "Physics/System/SHPhysicsSystem.h"
#include "Scene/SHSceneManager.h"
#include "Tools/Utilities/SHUtilities.h" #include "Tools/Utilities/SHUtilities.h"
namespace SHADE namespace SHADE
@ -53,12 +54,19 @@ namespace SHADE
{ {
const auto& COLLIDER_COMPONENT_DENSE = SHComponentManager::GetDense<SHColliderComponent>(); const auto& COLLIDER_COMPONENT_DENSE = SHComponentManager::GetDense<SHColliderComponent>();
for (const auto& COLLIDER_COMPONENT : COLLIDER_COMPONENT_DENSE) for (const auto& COLLIDER_COMPONENT : COLLIDER_COMPONENT_DENSE)
drawCollider(debugDrawSystem, COLLIDER_COMPONENT); {
if (SHSceneManager::CheckNodeAndComponentsActive<SHColliderComponent>(COLLIDER_COMPONENT.GetEID()))
drawCollider(debugDrawSystem, COLLIDER_COMPONENT);
}
} }
else if (!physicsDebugDrawSystem->collidersToDraw.empty()) else if (!physicsDebugDrawSystem->collidersToDraw.empty())
{ {
for (const auto EID : physicsDebugDrawSystem->collidersToDraw) for (const auto EID : physicsDebugDrawSystem->collidersToDraw)
drawCollider(debugDrawSystem, *SHComponentManager::GetComponent<SHColliderComponent>(EID)); {
if (SHSceneManager::CheckNodeAndHasComponentsActive<SHColliderComponent>(EID))
drawCollider(debugDrawSystem, *SHComponentManager::GetComponent<SHColliderComponent>(EID));
}
} }
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>(); auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();

View File

@ -239,6 +239,7 @@ namespace SHADE
// Unlink with managers // Unlink with managers
objectManager.SetPhysicsWorld(nullptr); objectManager.SetPhysicsWorld(nullptr);
collisionListener.ClearContainers();
return onSceneExitEvent.get()->handle; return onSceneExitEvent.get()->handle;
} }