Implemented a custom physics engine #316
|
@ -38,11 +38,7 @@
|
||||||
Position Offset: {x: 0, y: 0, z: 0}
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts:
|
Scripts: ~
|
||||||
- Type: PhysicsTestObj
|
|
||||||
Enabled: true
|
|
||||||
forceAmount: 50
|
|
||||||
torqueAmount: 500
|
|
||||||
- EID: 1
|
- EID: 1
|
||||||
Name: Default
|
Name: Default
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -81,7 +77,7 @@
|
||||||
Interpolate: true
|
Interpolate: true
|
||||||
Sleeping Enabled: true
|
Sleeping Enabled: true
|
||||||
Freeze Position X: false
|
Freeze Position X: false
|
||||||
Freeze Position Y: false
|
Freeze Position Y: true
|
||||||
Freeze Position Z: false
|
Freeze Position Z: false
|
||||||
Freeze Rotation X: false
|
Freeze Rotation X: false
|
||||||
Freeze Rotation Y: false
|
Freeze Rotation Y: false
|
||||||
|
@ -145,11 +141,7 @@
|
||||||
Position Offset: {x: 0, y: 0, z: 0}
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts:
|
Scripts: ~
|
||||||
- Type: PhysicsTestObj
|
|
||||||
Enabled: true
|
|
||||||
forceAmount: 50
|
|
||||||
torqueAmount: 500
|
|
||||||
- EID: 4
|
- EID: 4
|
||||||
Name: Default
|
Name: Default
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -190,11 +182,7 @@
|
||||||
Position Offset: {x: 0, y: 0, z: 0}
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts:
|
Scripts: ~
|
||||||
- Type: PhysicsTestObj
|
|
||||||
Enabled: true
|
|
||||||
forceAmount: 50
|
|
||||||
torqueAmount: 500
|
|
||||||
- EID: 5
|
- EID: 5
|
||||||
Name: Default
|
Name: Default
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -235,11 +223,7 @@
|
||||||
Position Offset: {x: 0, y: 0, z: 0}
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts:
|
Scripts: ~
|
||||||
- Type: PhysicsTestObj
|
|
||||||
Enabled: true
|
|
||||||
forceAmount: 50
|
|
||||||
torqueAmount: 500
|
|
||||||
- EID: 6
|
- EID: 6
|
||||||
Name: Default
|
Name: Default
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -280,8 +264,4 @@
|
||||||
Position Offset: {x: 0, y: 0, z: 0}
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
Scripts:
|
Scripts: ~
|
||||||
- Type: PhysicsTestObj
|
|
||||||
Enabled: true
|
|
||||||
forceAmount: 50
|
|
||||||
torqueAmount: 500
|
|
|
@ -159,7 +159,7 @@ public partial class LeafSearch : BehaviourTreeNode
|
||||||
//Since transform position is often the raccoon's base and the ray needs to hit somewhere higher to be more reliable
|
//Since transform position is often the raccoon's base and the ray needs to hit somewhere higher to be more reliable
|
||||||
Vector3 rayDestination = plrT.GlobalPosition + plrT.GlobalScale * playerCollider.PositionOffset;
|
Vector3 rayDestination = plrT.GlobalPosition + plrT.GlobalScale * playerCollider.PositionOffset;
|
||||||
Ray sightRay = new Ray(eyePosition, rayDestination - eyePosition);
|
Ray sightRay = new Ray(eyePosition, rayDestination - eyePosition);
|
||||||
RaycastHit sightRayHit = Physics.Raycast(sightRay);
|
RaycastHit sightRayHit = Physics.Raycast(sightRay, false)[0];
|
||||||
//As of November 2022, RaycastHit contains only the FIRST object hit by
|
//As of November 2022, RaycastHit contains only the FIRST object hit by
|
||||||
//the ray in the Other GameObject data member
|
//the ray in the Other GameObject data member
|
||||||
//Diren may likely add ALL objects hit by the ray over December
|
//Diren may likely add ALL objects hit by the ray over December
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using SHADE;
|
using SHADE;
|
||||||
using SHADE_Scripting;
|
using SHADE_Scripting;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using static PlayerController;
|
using static PlayerController;
|
||||||
using static Item;
|
using static Item;
|
||||||
|
|
||||||
|
@ -203,9 +204,13 @@ public class PickAndThrow : Script
|
||||||
Vector3 playerRayPos = pc.tranform.GlobalPosition;
|
Vector3 playerRayPos = pc.tranform.GlobalPosition;
|
||||||
playerRayPos.y += 0.05f;
|
playerRayPos.y += 0.05f;
|
||||||
dirNor.Normalise();
|
dirNor.Normalise();
|
||||||
RaycastHit ray1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance);
|
List<RaycastHit> rayList1 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(22.5f))), rayDistance, false);
|
||||||
RaycastHit ray2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance);
|
List<RaycastHit> rayList2 = Physics.Raycast(new Ray(playerRayPos, Vector3.RotateY(dirNor, SHADE.Math.DegreesToRadians(-22.5f))), rayDistance, false);
|
||||||
RaycastHit ray3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f);
|
List<RaycastHit> rayList3 = Physics.Raycast(new Ray(playerRayPos, dirNor), rayDistance * 0.75f, false);
|
||||||
|
|
||||||
|
RaycastHit ray1 = rayList1[0];
|
||||||
|
RaycastHit ray2 = rayList2[0];
|
||||||
|
RaycastHit ray3 = rayList3[0];
|
||||||
inRange = CheckForItem(ray1) || CheckForItem(ray2) || CheckForItem(ray3);
|
inRange = CheckForItem(ray1) || CheckForItem(ray2) || CheckForItem(ray3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ using static Item;
|
||||||
|
|
||||||
public class PhysicsTestObj : Script
|
public class PhysicsTestObj : Script
|
||||||
{
|
{
|
||||||
public RigidBody rb { get; set; }
|
public RigidBody body { get; set; }
|
||||||
|
public Collider collider { get; set; }
|
||||||
|
|
||||||
// Movement input booleans
|
// Movement input booleans
|
||||||
public enum Direction
|
public enum Direction
|
||||||
|
@ -67,7 +68,8 @@ public class PhysicsTestObj : Script
|
||||||
|
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
rb = GetComponent<RigidBody>();
|
body = GetComponent<RigidBody>();
|
||||||
|
collider = GetComponent<Collider>();
|
||||||
|
|
||||||
for (int i = 0; i < 6; ++i)
|
for (int i = 0; i < 6; ++i)
|
||||||
{
|
{
|
||||||
|
@ -78,6 +80,10 @@ public class PhysicsTestObj : Script
|
||||||
|
|
||||||
protected override void update()
|
protected override void update()
|
||||||
{
|
{
|
||||||
|
Ray colliderRay = new Ray();
|
||||||
|
colliderRay.Direction = Vector3.Right;
|
||||||
|
Physics.ColliderRaycast(collider.Owner, colliderRay, false);
|
||||||
|
|
||||||
for (int i = 0; i < 6; ++i)
|
for (int i = 0; i < 6; ++i)
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(moveInputKeys[i]))
|
if (Input.GetKeyDown(moveInputKeys[i]))
|
||||||
|
@ -99,13 +105,13 @@ public class PhysicsTestObj : Script
|
||||||
{
|
{
|
||||||
//Vector3 offset = new Vector3(0.25f, 0.0f, 0.0f);
|
//Vector3 offset = new Vector3(0.25f, 0.0f, 0.0f);
|
||||||
//rb.AddForceAtLocalPos(moveVec[i] * forceAmount, offset);
|
//rb.AddForceAtLocalPos(moveVec[i] * forceAmount, offset);
|
||||||
rb.AddForce(moveVec[i] * forceAmount);
|
body.AddForce(moveVec[i] * forceAmount);
|
||||||
move[i] = false;
|
move[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRotate)
|
if (shouldRotate)
|
||||||
{
|
{
|
||||||
rb.AddTorque(rotateVec[i] * torqueAmount);
|
body.AddTorque(rotateVec[i] * torqueAmount);
|
||||||
rotate[i] = false;
|
rotate[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,6 +220,10 @@ namespace SHADE
|
||||||
if (ImGui::Checkbox("Draw Contact Points", &drawContactPoints))
|
if (ImGui::Checkbox("Draw Contact Points", &drawContactPoints))
|
||||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS, drawContactPoints);
|
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS, drawContactPoints);
|
||||||
|
|
||||||
|
bool drawRays = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS);
|
||||||
|
if (ImGui::Checkbox("Draw Rays", &drawRays))
|
||||||
|
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS, drawRays);
|
||||||
|
|
||||||
bool drawBroadphase = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE);
|
bool drawBroadphase = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE);
|
||||||
if (ImGui::Checkbox("Draw Broadphase", &drawBroadphase))
|
if (ImGui::Checkbox("Draw Broadphase", &drawBroadphase))
|
||||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE, drawBroadphase);
|
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE, drawBroadphase);
|
||||||
|
|
|
@ -87,8 +87,14 @@ namespace SHADE
|
||||||
|
|
||||||
if (DRAW_RAYCASTS)
|
if (DRAW_RAYCASTS)
|
||||||
{
|
{
|
||||||
// TODO
|
const SHColour& RAY_COLOUR = physicsDebugDrawSystem->DEBUG_DRAW_COLOURS[SHUtilities::ConvertEnum(Colours::RAYCAST)];
|
||||||
physicsDebugDrawSystem->raysToDraw.clear();
|
|
||||||
|
const auto& RAYS = physicsSystem->raycastHits;
|
||||||
|
for (const auto& hit : RAYS)
|
||||||
|
debugDrawSystem->DrawLine(hit.start, hit.end, RAY_COLOUR, true);
|
||||||
|
|
||||||
|
// Clear rays for the physics system
|
||||||
|
physicsSystem->raycastHits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DRAW_BROADPHASE)
|
if (DRAW_BROADPHASE)
|
||||||
|
|
|
@ -149,11 +149,4 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawRaycast(SHDebugDrawSystem* debugDrawSystem, const DebugDrawInfo::Raycast& raycastInfo) noexcept
|
|
||||||
{
|
|
||||||
static const SHColour& DRAW_COLOUR = DEBUG_DRAW_COLOURS[SHUtilities::ConvertEnum(Colours::RAYCAST)];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -131,8 +131,6 @@ namespace SHADE
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
|
|
||||||
Colliders collidersToDraw;
|
Colliders collidersToDraw;
|
||||||
Raycasts raysToDraw;
|
|
||||||
Contacts contactToDraw;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Member Functions */
|
/* Member Functions */
|
||||||
|
|
Loading…
Reference in New Issue