Devlog - Custom Physics and Collisions
Custom Physics and Collisions
By Dexter
A lot of playtesters ask us how we implement our 3D to 2D magic! So we present you this devlog to quickly showcase our methods to our madness. Let's take a look at what our CS team cooked up.
An important mechanic in our game is the player’s ability to switch between 2D and 3D at will. Because of this, our game’s collision detection needs to work 2 (for now, at least) different ways. Sometimes, we want 3D collisions which the Unity engine already implements just fine, but other times we want to handle collisions according to the 2D projection of all the 3D objects into a plane.
Constraints and Affordances
Because of how the default Unity physics are implemented, a physics object and its collider must have the same position (you really have to fight against the engine to make it work a different way). Additionally, the physics system is very opaque and it is not very feasible to modify its behaviour at any particular step. There are some ways of emulating 2D collision detection using Unity’s default 3D physics system which we explored: It is possible to extend certain colliders very far along an axis so that they collide with objects regardless of their position along that axis. However, this doesn’t work for every type of collider (spheres can’t be scaled this way, for example). It is also possible to move every object from its “real” position to the projection of its position onto a plane when the player switches to 2D and then move everything back to its “real” when the player switches back to 3D, but this won’t produce accurate collisions as colliders may extend out of the plane.
Diagram of why we can’t just project the positions of objects onto the plane
Our Solution
It is definitely possible to fight against the Unity engine and end up with a good implementation of this mechanic, but it would be unnecessarily difficult. Instead, we used the Psyshock physics library which implements all the lower-level details of a physics system (collision checks between primitive shapes, a BVH structure, and more) but is structured such that we have control at each step of the collision detection process. This way, instead of having each collider “attached” to its associated physics object, our implementation has total control over the colliders. This means that we can project the colliders and their positions into 2D without workarounds like moving the actual game objects or scaling them.
Having a separate collision detection system which works for both 2D and 3D means we can implement the dimension switching mechanic without needing workarounds that might bleed into other parts of the game.
Get Dimensional Drift
Dimensional Drift
Status | Released |
Authors | crELu, igobykuro, hellerni, fmwofmwmf, reriss, caspian9, kayliphobia, stormshadow3155 |
Genre | Shooter, Action |
Tags | 2D, 3D, Arcade, Bullet Hell |
More posts
- Devlog - Player Overhaul & Tutorial16 days ago
- Devlog - Updated Environment & More Enemies16 days ago
- Devlog - Rocket, Sounds & Shop16 days ago
- Devlog - Currency, New Enemies & Weapons16 days ago
- Devlog - Dimension Transition & Collisions17 days ago
- Devlog - Enemy AI & Models17 days ago
- Devlog - Weapon Planning17 days ago
- Devlog - Shooting, Dimension Switching & Experiments17 days ago
- Devlog - Conception & Prototyping17 days ago
Leave a comment
Log in with itch.io to leave a comment.