Nature2D - 2D Physics Engine for UI Elements

You can make almost anything that has to do with collisions or physics in general. This makes it easy to make stuff like people’s playground, construction based educational/adventure games, pong games, slither io games, physics based platformers etc.

It all lies within the infinite boundaries of imagination!

10 Likes

awesome, probably going to make a yt tutorial on this to help out a bit
thanks for the reply

9 Likes

Pretty cool! But I’m wondering how this would do on high frame-rates?

4 Likes

This is cool!
Now we are getting Unity2D in roblox. I’m just kidding.
This is actually awesome!

9 Likes

It should do well, although I haven’t tested it yet. It may result in the simulations being a bit faster. If you encounter any undesired behavior, you can open an issue in the github repository or alert me here.

Thanks for bringing this up, I’ll make the use of detlaTime (I should have from the start >_<) and push the update sooner or later!

7 Likes

Amazing resource. If something like this was around (or if I was as bigbrain as OP to implement this myself) when I was making my game Calmfall, I would’ve made it 2D! Thank you for the resource OP

6 Likes

v0.0.1 - Improvements & New Methods

Slowly improving custom Constraints support.

  • Improved architecture for anchored RigidBodies.
  • Constraints now have their own unique IDs like RigidBodies.
  • Added new Methods to Constraints
    • Constraint:GetLength()
    • Constraint:Destroy()
  • Added new Methods to Engine
    • Engine:GetConstraints()
    • Engine:GetConstraintById()
  • Added new Methods to RigidBodies
    • RigidBody:SetFriction()
    • RigidBody:SetGravity()

Updates to Documentation - Updated


3 Likes

This is so amazing! This will enable some really cool things to be done with GUI, such as more natural animations. It will also enable some cool interactions with GUI… like replacing the Backpack GUI with a dynamic item shelf at the bottom of the screen, where items can be dragged around and can be dragged onto other items to interact with them, as well as dragged onto certain 3D things to interact with them (e.g. dragging a key onto a locked door to unlock the door) Cool stuff!

3 Likes

v0.0.2 - Custom Point Support, Configuration Methods and More!

  • Installation through Wally! Nature2D can now be installed using Wally, the package manager for Roblox. This requires wally to be installed on your device. In order to install Nature2D, add a dependency to your wally.toml file
    • image

    • After you have added the dependency, run wally install in the command line. A “Packages” directory is created containing the library. You can now use Nature2D in your external editor using wally!


  • Bug Fixes
    • Linked Issue: #1
  • Engine:CreateCanvas() now has an optional ‘frame’ parameter to help render custom points and constraints.
  • Refactored certain segments of code for better readability.

  • Added Custom Point support to Engine
    • Engine:CreatePoint()
    • Engine:GetPoints()
  • Added new Configuration methods to Constraints
    • Constraint:Stroke()
  • Added new Configuration methods to Points
    • Point:SetRadius()
    • Point:Stroke()
    • Point:Snap()

Updates to Documentation - Updated

Update Wally package - Updated



Documentation will be updated soon. New examples and tutorials will also be added so look out for those at the github repository!

4 Likes

Note for the 2 people that read down here.

This will bug with seperate framerates. I.E: Higher than 60 will run faster than normal, and lower than 60 will… just use your brain.

But yeah this is really sick. I give it the Official LemonyPep Seal Of Quality. Because that exists now.

3 Likes

Correct, this will be fixed in the upcoming versions though! Thanks.

2 Likes

The engine is now frame-rate independent!

Earlier: Simulations running on different frame rates had a difference in their speeds. A simulation running on 60fps would run faster than that of a simulation running at 30fps.

Now: Frame-rate no longer affects simulations. A RigidBody covering a distance of 10 units in a simulation running at 30fps and a simulation running 60fps will take almost the same time to reach the destination.

Note: This hasn’t been tested with multiple kinds of simulations. Thus, if you encounter any unwanted behavior, errors or visual bugs - you can open an issue at the github repository!

Wally Package Updated: 0.0.2 → 0.0.3
Roblox Model Updated
Github Repository Updated


More feature rich updates soon. Contribution is also welcome! Documentation will be updated in response to the previous updates, soon!

5 Likes

v0.0.4 Engine:SetSimulationSpeed() & Documentation

  • Updated API-References for RigidBodies, Constraints, Points and Engine in response to this and previous updates.
  • Documented source code with comments.
  • Better error handling and error messages.
  • Fixed Engine:SetPhysicalProperty() bug where updating a physical property before creating a rigidbody did not change the properties for the rigidbody.
  • Added new Methods to Engine

Updated Documentation

Wally Package Updated - 0.0.3 → 0.0.4

Roblox Model Updated


2 Likes

No way! Finally what I always wanted! Now I don’t have to script gui collisions anymore

I really wanted this for like 3 years all I could do is 3d, but now it’s finally here

2 Likes

I have been messing around with this a little and it’s pretty cool! Although I did run into two issues:

  • There’s a lot of lag when there is a large amount of RigidBodies (I was able to fix this on my own by editing the collision checking code to only check for collisions on anchored bodies if the other body is not anchored)

  • If an unanchored RigidBody is in a position where it should seemingly not be moved by physics (on top of an anchored RigidBody, for example), it will be continuously moved by a small amount to the left/right every few frames

This resource would be incredibly useful if these issues were to be fixed!

3 Likes

Hey, thanks for the feedback!

The large amount of lag is purely due to collision detection. In the next coming updates, I would be switching to quadtrees for iterating through the rigidbodies during collision detection, to make the engine 10 times faster!

The 2nd issue is known, well, to be honest that’s just how verlet integration works! A work around would be to set friction of all rigidbodies stacked on top of each other to 0 (RigidBody:SetFriction()) and then set it back to normal when some other body collides with it, etc. But yes, this is something I wish to fix in the future!

5 Likes

This is really cool. It opens a whole range of new ideas I can try, definitely will implement this in my projects

4 Likes

Very impressive. Glad to see more people contributing towards the 2D development scene considering it’s neglected by Roblox.

2 Likes

v0.0.5 - Fixes and New Stuff!

  • The library now utilizes sleitnick’s Signal class instead of bindable events.
    • RigidBody.CanvasEdgeTouched:Connect()
    • RigidBody.Touched:Connect()
  • Bug Fixes
    • Error Handling
  • Improved code - Removed bad practices
  • RigidBody.CanvasEdgeTouched event returns the edge the RigidBody collides with, a string which is one of the following: Top, Bottom, Left and Right.
  • Added new methods to Engine

Added new example which covers the concept of creating Custom Constraints, where we create the following simulation of a RigidBody hanging from a rope, and wind forces being applied on it.

Jump to Example

rope


Updated Documentation

Updated Roblox Model & Github

Updated Wally Package - 0.0.4 → 0.0.5



In the next few updates, I’ll try to implement Quadtrees in the collision detection algorithm to improve performance and make the library 10 times faster!

2 Likes

v0.1.0 - Additions to Constraints, Engine and RigidBodies.

  • Added new methods to Constraints
  • Added new methods to RigidBodies
  • Added new events to Engine
    • Engine.Started
    • Engine.Stopped
engine.Started:Connect(function()
    -- fires when the engine starts
end)

engine.Stopped:Connect(function()
    -- fires when the engine stops
end)

Documentation Updated

Roblox Model and Github Updated

Wally Package Updated - 0.0.5 → 0.1.0


Check out some stuff I made in the past weekend with Nature2D! The game of Plinko and a weight bearing flexible bridge by connecting RigidBodies with constraints!




Quality updates soon. Next updates will be regarding the implementation of quadtrees in collision detection. If anything breaks, open an issue at the github repository!

5 Likes