Repository navigation
nbphysics (v1.0.0)
Description
nbphysics is a 2D hybrid physics engine made for GameMaker in GameMaker Studio 2 LTS. It supports collision detection and resolution of non-rotated rectangles, rotated rectangles, and circles. I made it because I plan to use it in my future games so it should get better over time!
Features
- Physics worlds: objects that keep track of and update rigid bodies and triggers
- Rigid bodies: the physics objects that are affected by forces and collisions
- Triggers: Can detect the entering and exiting of rigid bodies
- 3 supported shapes: rectangles, rotated rectangles and circles
- Various built-in force generators such as springs, buoyancy and wind
- Various built-in collision generators such as instance collisions (with supported shapes), rods and cables
- A fully functional demo platformer
- Various other demos showcasing different parts of the engine
- 2 bitmask layers for collisions: one for where objects 'live', the other for what they can collide with
- No current torque handling, but there is rotation handling
- Sleep system for rigid bodies to improve performance
- Vector2 and 2x2 Matrix structs
- Support for custom force and contact generators
- Support for custom forces using nbpAddForce anywhere
- Support for multiple physics worlds
- Global functions for manipulating rigid bodies, physics worlds and triggers
- Adjustable simulation speed
How to use
You can look at the demos to give you an idea of how to work with it. Generally:
- instantiate a physics world
- create rigid bodies (they'll automatically get recognized by the physics world)
- create force and contact generators
- link the generators to the desired bodies (using nbpAddForceGen() or nbpAddContactGen())
- (optional) create a trigger and link it to the rigid body
And that's it! The generators should apply the forces/check collisions every frame. When you're done with a rigid body, you can safely destroy it!