Releases: jaipack17/Nature2D
.TouchEnded Event
- Added
.TouchEnded
event to RigidBodies. This event fires the moment two RigidBodies stop colliding with each other. - Fixed AnchorPoint bug with anchored RigidBodies. Anchored RigidBodies can now have any AnchorPoint, which does not affect how they are positioned on the screen.
Improvements to .Touched
- Improvements to .Touched Event. The event does not fire every frame anymore if two bodies are colliding. It'll only fire the moment the two bodies collide. Playing collision sounds etc is now possible.
RigidBody:Destroy()
now takes in an optional argument "keepFrame: boolean|nil". If passed in as true, the RigidBody's UIElement will not be destroyed. If passed as false or nil, the RigidBody's UIElement will be destroyed along with it.- Changes to Signal utility. Curtsy of @LucasMZReal
- Made Connection property .Connected public
Nature2D Plugins/Utility Modules
Nature2D Plugins/Utility Modules
- Added new methods to Points
Point:SetMaxForce(maxForce: number)
- Added new methods to RigidBodies
RigidBody:SetMaxForce(maxForce: number)
- Added Plugins
- Quad
- Triangle
- MouseConstraint
More about Plugins here: https://devforum.roblox.com/t/nature2d-2d-physics-library-for-ui-elements/1510935/64
Support for different Masses of RigidBodies
Support for different Masses of RigidBodies
- Added the ability to set a mass value other than 1 for different RigidBodies
- Added new methods to RigidBodies
RigidBody:SetMass()
- Updated
Point:ApplyForce()
andRigidBody:ApplyForce()
. Divides the force by the RigidBody's mass to calculate acceleration. - Updated Collision detection and response to have effects according to the masses of each RigidBody. Now calculates accurate ratios for the force applied to each body after collision.
- Cleaned some code, replaced bad practices with good ones, used Vector2:Dot() which is slightly faster than calculating the dot product of two vectors from scratch.
Custom RigidBody Support!
Custom RigidBody Support.
- Fixed
Engine:CreateCanvas()
- Canvas' can now be re-initialized. - Fixed
Constraint:Render()
- Prevent support constraints from rendering - Added support for custom RigidBodies
- Added new Valid Property for RigidBodies -
Structure: table
- Updated Collision Detection and Response to work with custom RigidBodies
- Updated
Engine:Create()
- Restrict certain methods from being used for custom RigidBodies
You can now create more than just rectangles and squares. You can now define your own point-constraint structures like triangles, irregular quadrilaterals and n-sided polygons and then turn them into RigidBodies!
Improvements to :ApplyForce(). New events & methods
New Events, Methods and Improvements
- Added new events to Engine
Engine.ObjectAdded
- Fires when a new Point, Constraint or RigidBody is created.Engine.ObjectRemoved
- Fires when a new Point, Constraint or RigidBody is destroyed.
- Added new methods to RigidBodies
RigidBody:GetTouchingRigidBodies()
- Returns all RigidBodies that are in collision with the current RigidBody.
- API Changes to
Point:ApplyForce()
andRigidBody:ApplyForce()
- Added a second optional parameter 'time'.
- The time parameter can be used to apply a force for a certain amount of time.
- Example:
Body:ApplyForce(Vector2.new(.4, 0), 3) -- applies the force for 3 seconds
Ability to clone RigidBodies
Ability to clone RigidBodies
Added the ability to clone already existing RigidBodies! By default the clone won't inherit the original RigidBody's states, lifespan or filtered RigidBodies. In order to copy those too, pass in the deepCopy parameter as true!
- Added
RigidBody:Clone(deepCopy: boolean | nil)
New Valid Properties, API Changes and Improvements
New Valid Properties, API Changes and Improvements
- Changes to
RigidBody:SetPosition()
,RigidBody:SetSize()
andPoint:SetPosition()
- These methods no longer take in a Vector2 value, rather individual x and y values.
- Example:
RigidBody:SetPosition(100, 100)
,RigidBody:SetSize(20, 40)
andPoint:SetPosition(500, 0)
- Improvement how RigidBody lifespans work. They no longer use
os.time()
.os.clock()
is now used thus high precision values for RigidBody lifespans work too! - Fixed
Point:Render()
andConstraint:Render()
- Added checks to see if Engine's canvas has a frame. - Added new Valid properties to
Engine:Create()
. You can now pass in this properties toEngine:Create()
. - New valid properties for Points
KeepInCanvas: boolean | nil
Color: Color3 | nil
Radius: number | nil
- New valid properties for Constraints
SpringConstant: number | nil
Color: Color3 | nil
- New valid properties for RigidBodies
LifeSpan: number | nil
KeepInCanvas: boolean | nil
Gravity: Vector2 | nil
Friction: number | nil
AirFriction: number | nil
Refactored Object Creation Completely
Major Release.
- Removed
Engine:CreatePoint()
- Removed
Engine:CreateConstraint()
- Removed
Engine:CreateRigidBody()
- Added
Engine:Create(objectName: string, propertyTable: table)
Creating new Constraints, Points and RigidBodies is much simpler than before! You just need to care about 1 single method - Engine:Create()
. This method takes in 2 parameters. The first parameter being the type of instance you are creating. This is either "Point", "Constraint" or "RigidBody". The second parameter consists of the properties you wish to assign to the object.
Intellisense of VSCode and Studio's script editor will suggest these properties to you!
engine.create.method.mp4
- Changed how you require Nature2D.
- Earlier:
require(ReplicatedStorage.Nature2D.Engine)
- Now:
require(ReplicatedStorage.Nature2D)
- Earlier:
- Added "Snap" to a valid property of
Point
- API cleanup
- Rewrote commented docs in the source code.
- Fixed
Point:Render()
- Set point's anchor point to 0.5, 0.5 - Fixed Rod Constraints and how I solve them - See issue #8
Collision Filtering
Implemented basic collision filtering API for RigidBodies! You can now specify other RigidBodies a body collides with, if not all!
- Added Collision Filtering to Engine
- Added new Methods to RigidBodies
Engine:FilterCollisionsWith(otherRigidBody: RigidBody)
Engine:UnfilterCollisionsWith(otherRigidBody: RigidBody)
Engine:GetFilteredRigidBodies()