Merge pull request #350 from SHADE-DP/SP3-2-Physics

Potential fix for incorrect collision states
This commit is contained in:
XiaoQiDigipen 2023-02-04 15:20:14 +08:00 committed by GitHub
commit e07a741c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 221 additions and 16 deletions

View File

@ -1,18 +1,18 @@
- EID: 0
Name: Default
Name: Player
IsActive: true
NumberOfChildren: 0
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
@ -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
@ -39,6 +39,8 @@
Enabled: true
forceAmount: 50
torqueAmount: 500
- Type: CollisionTest
Enabled: true
- EID: 1
Name: Default
IsActive: true
@ -52,7 +54,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 +163,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
@ -208,3 +210,26 @@
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: ~

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

@ -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<Transform>();
body = GetComponent<RigidBody>();
collider = GetComponent<Collider>();
@ -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<Transform>().GlobalPosition, false, (ushort)64);
}
for (int i = 0; i < 6; ++i)
{

View File

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

View File

@ -0,0 +1,3 @@
Name: TriggerTest
ID: 159344038
Type: 9

View File

@ -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<SHColliderComponent>();
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())
{
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>();

View File

@ -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

View File

@ -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 */
/*-----------------------------------------------------------------------------------*/
/// <summary>
/// Represents a collision tag.
/// </summary>
public ref struct CollisionTag sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Name of the object that this Entity represents.
/// </summary>
property System::String^ Name
{
System::String^ get();
void set(System::String^ value);
}
property unsigned short Mask
{
unsigned short get();
}
/*-----------------------------------------------------------------------------*/
/* Property Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Checks the state of a layer on the mask.
/// </summary>
/// <param name="layer">The layer to check.</param>
/// <returns>True if the state is active.</returns>
bool GetLayerState (int layer);
/// <summary>
/// Sets the state of a layer on the mask.
/// </summary>
/// <param name="layer">The layer to set.</param>
/// <param name="state">The state of the layer to set.</param>
void SetLayerState (int layer, bool state);
};
public ref class CollisionTagMatrix abstract sealed
{
public:
/*---------------------------------------------------------------------------------*/
/* Member Functions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Get the name of a Collision Tag
/// </summary>
/// <param name="tagIndex">
/// The index of the tag in the matrix.
/// </param>
/// <returns>The name of the collision tag.</returns>
System::String^ GetTagName(int tagIndex);
int GetTagIndex(System::String^ tagName);
};
}