Github・Roblox Model・Documentation・API Reference・Tutorials
Nature2D is a 2D physics library designed for and on Roblox! Ever wanted to create 2D games but step back because Roblox doesn’t have a built-in 2D physics engine? Use Nature2D to create versatile and smooth simulations and mechanics for your 2D games with minimum effort! Nature2D primarily uses methods of Verlet Integration and Convex Hull collisions.
It’s user friendly and supports all UI Elements. RigidBodies and constraints can potentially be made with almost all UI elements, from Frames to TextBoxes. Collision detection and response are also handled for all UI elements by default.
Create almost anything you can imagine. From bouncy boxes to destructible structures, even character movement in no time. Here’s a wrecking ball connected to an invisible constraint knocking a few boxes off of the blue platform.
External Forces like Wind
It is important to know how the library really comes together and do what its supposed to do. The library uses methods of Verlet Integration and Convex Hull Collisions (Separating Axis Theorem) to simulate physics. I have detailed the math and working of both of those methods on the Devforum and Github with code snippets. If you’d want to explore more about them, go through the following links.
The library is divided into different segments. The core, which is the Engine. The physics based classes, which are the RigidBodies, Constraints and Points, utilities which consists of non inclusive modules to help render constraints and points on the screen and global constant values.
The Engine or the core of the library handles all the RigidBodies, constraints and points. It’s responsible for the simulation of these elements and handling all tasks related to the library. Physics is simulated every RenderStepped with the following structure:
All tasks are performed in order as seen in the picture above.
Points are what make the rigid bodies behave like real world entities. Points are responsible for the movement of the RigidBodies and Constraints. These points are not rendered on the screen by default and it is advisable to keep it that way. Points don’t need to be created manually unless creating custom Constraints. By default, points are handled by the core (Engine) itself.
Constraints keep two points together in place and maintain uniform distance between the two. Constraints and Points together join to keep a RigidBody in place hence making both Points and Constraints a vital part of the library. Custom constraints such as Ropes, Rods, Bridges and chains can also be made. Points of two rigid bodies can be connected with constraints, two individual points can also be connected with constraints to form Ropes etc.
RigidBodies are formed by Constraints, Points and UI Elements. These RigidBodies are highly flexible to meet all your use cases. RigidBodies can be customized and custom physical properties can be defined for them. By default they abide by the universal physical properties of the engine. RigidBodies as of now cannot have different masses. An update has been planned to support this.
Regarding performance, Nature2D does just fine for almost any game. Every RenderStepped event, actions take place, as described above. Performance varies according to the amount of RigidBodies and constraints being simulated. It also depends upon how many collisions take place in between ‘n’ number of RigidBodies.
It runs at 60fps with an average of 100 collisions every frame. Frames may drop, if RigidBodies are used as particle emitters or large scale simulations. Its advisable to use custom 2D Particle Emitters instead of RigidBodies due to frame drops.
In terms of physical accuracy, Nature2D does well. It’s not and isn’t meant to be completely physically accurate since that’s near to impossible but I do plan on improving a lot of things that make it resemble the real world much better. Few things that I would improve is the friction.
Friction currently is just a damping value, I do plan on refactoring it. (Refactored)
Collisions are not necessarily physically accurate. They are meant to have a game-like vibe. I do plan on refactoring it as well.
Nature2D is still in BETA. Thus, bugs, mistakes in the code are natural. If you spot any, you can open an issue on github or alert me over here in the replies. I’ll frequently update this resource. If you wish to contribute to this resource, head over to the github repository, fork it and open a pull request!
I hope you enjoy these posts and resources and I hope they help out some of you. If you wish to support these projects, chuck them a star! Stick around for more since there are a lot of new updates, projects and resources coming around!
You can follow my twitter. I post future and new updates for my projects as well as some cool creations!
Thanks for reading!
If you encounter bugs or would like to support this project by improving the code, adding new features or fixing bugs - Feel free to open issues and pull requests! Also read the contribution guide!