diff --git a/README.md b/README.md index d71f6cd..965b6a6 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,9 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender - [ ] Ambient background loop ## Current Bug TODO List (Hardware Verified) (High->Low priority) -- [ ] Player can clip through any level by placing one portal on wall and another portal right next to it on ground. #13 - [ ] Player can clip through chamber 7 by walking back up the stairs (near the top). - [ ] player can clip through back of elevator by jumping and strafeing at the back corners while inside. -- [ ] Player can strap themselves in chamber 5 by following instructions issue #75 -- [ ] Any grabbable object can be clipped through level by wall/floor portals method. +- [ ] Player can trap themselves in chamber 5 by following instructions issue #75 - [ ] Two wall portals next to eachother can be used to clip any object out of any level by pushing it into corner, then dropping. - [ ] Glass can be walked through from one side on multiple levels (0,1,4,...) - [ ] Passing into a ceiling portal can sometimes mess with the player rotation @@ -139,5 +137,6 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender - [ ] Door at end of room 2, chamber 10 isnt rendered properly - [ ] various visual glitches when running NTSC on PAL console #65 - [ ] various visual glitches when running PAL on NTSC console #65 -- [x] Can shoot portals while holding an object - +- [x] Any grabbable object can be clipped through level by wall/floor portals method. +- [x] Player can clip through any level by placing one portal on wall and another portal right next to it on ground. #13 +- [x] Can shoot portals while holding an object \ No newline at end of file diff --git a/src/physics/rigid_body.c b/src/physics/rigid_body.c index ac4209e..6fd8f8b 100644 --- a/src/physics/rigid_body.c +++ b/src/physics/rigid_body.c @@ -82,6 +82,24 @@ float rigidBodyMassInverseAtLocalPoint(struct RigidBody* rigidBody, struct Vecto return rigidBody->massInv + rigidBody->momentOfInertiaInv * vector3MagSqrd(&crossPoint); } +void rigidBodyClampToPortal(struct RigidBody* rigidBody, struct Transform* portal) { + struct Vector3 localPoint; + + transformPointInverseNoScale(portal, &rigidBody->transform.position, &localPoint); + + //clamping the x and y of local point to a slightly smaller oval on the output portal + struct Vector3 clampedLocalPoint; + clampedLocalPoint = localPoint; + clampedLocalPoint.y /= 2.0f; + clampedLocalPoint.z = 0.0f; + while(sqrtf(vector3MagSqrd(&clampedLocalPoint))>PORTAL_EXIT_XY_CLAMP_DISTANCE){ + vector3Scale(&clampedLocalPoint, &clampedLocalPoint, 0.90f); + } + clampedLocalPoint.y *= 2.0f; + localPoint.x = clampedLocalPoint.x; + localPoint.y = clampedLocalPoint.y; + transformPoint(portal, &localPoint, &rigidBody->transform.position); +} int rigidBodyCheckPortals(struct RigidBody* rigidBody) { if (!gCollisionScene.portalTransforms[0] || !gCollisionScene.portalTransforms[1]) { @@ -94,6 +112,14 @@ int rigidBodyCheckPortals(struct RigidBody* rigidBody) { enum RigidBodyFlags newFlags = 0; + //if only touching one portal, clamp object to edges of that portal + if ((rigidBody->flags & RigidBodyIsTouchingPortalA) && !(rigidBody->flags & RigidBodyIsTouchingPortalB)){ + rigidBodyClampToPortal(rigidBody, gCollisionScene.portalTransforms[0]); + } + else if ((rigidBody->flags & RigidBodyIsTouchingPortalB) && !(rigidBody->flags & RigidBodyIsTouchingPortalA)){ + rigidBodyClampToPortal(rigidBody, gCollisionScene.portalTransforms[1]); + } + if (rigidBody->flags & RigidBodyIsTouchingPortalA) { newFlags |= RigidBodyWasTouchingPortalA; } diff --git a/src/physics/rigid_body.h b/src/physics/rigid_body.h index 2b18c24..fd161ba 100644 --- a/src/physics/rigid_body.h +++ b/src/physics/rigid_body.h @@ -3,6 +3,7 @@ #include "../math/basis.h" #include "../math/transform.h" +#include "../math/mathf.h" #include "./collision.h" #define KILL_PLANE_Y -10.0f @@ -10,6 +11,7 @@ #define RIGID_BODY_NO_ROOM 0xFFFF #define MAX_PORTAL_SPEED (1000.0f / 64.0f) +#define PORTAL_EXIT_XY_CLAMP_DISTANCE (0.15f) enum RigidBodyFlags { RigidBodyFlagsInFrontPortal0 = (1 << 0),