Potential fix for incorrect collision states #350

Merged
direnbharwani merged 5 commits from SP3-2-Physics into main 2023-02-04 15:20:14 +08:00
5 changed files with 156 additions and 7 deletions
Showing only changes of commit 7cf5ef4b81 - Show all commits

View File

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

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

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