Releases: jaipack17/Nature2D
Anchor Point Support
Anchor Point Support
- Added Anchor point support
- Added new methods to RigidBodies
RigidBody:GetCenter()
- Added new methods to Points
Point:SetPosition(newPosition: Vector2)
- Bug fixes
- Fixed Parent hierarchy errors in Points.
- Fixed
Point:Update()
"Cannot read property 'Parent' of nil" errors. - Fixed
Point:KeepInCanvas()
"Cannot read property 'Parent' of nil" errors.
Major Improvements to Frictional Forces
Major Improvements to Frictional Forces
Linked Pull Request - #4
- Fixed a bug where changes to physical properties before creating any RigidBodies, Constraints or Points won't affect/apply to newly created objects.
- Friction only applies if RigidBodies collide with each other or the edges of the canvas. If none of those conditions are true, AirFriction is applied.
- Added AirFriction physical property to Engine, Points and RigidBodies. Frictional force applied when a RigidBody neither touches another body nor the edges of canvas.
Engine:SetPhysicalProperty("AirFriction", 0.1)
- Friction and AirFriction are set to 0.01 by default. (0.99 damping value).
- Changed how we pass parameters when initializing or updating friction of the engine or rigidbodies. The closer the friction to 1, the higher it is. The closer the friction to 0, the lower it is. Same applies for AirFriction. Values not in the range of 0-1 are automatically clamped down.
- Added new Methods to RigidBodies
RigidBody:SetAirFriction(airfriction: number)
Fixes to Collision Detection & New Methods
Fixes to Collision Detection & New Methods
- Made
restLength: number?
an optional parameter forEngine:CreateConstraint()
. - Fixes to Collision Detection - Collision detection is no longer skipped at low frame rates.
- Fixed how forces are applied to Points when the engine is framerate independent.
- Added new methods to Engine
Engine:FrameRateIndependent(independent: boolean)
- Determines if Frame rate does not affect the simulation speed. By default set to true.
- Added new methods to Constraint
Constraint:GetParent()
- Added new methods to Point
Point:GetParent()
New Constraint Types!
v0.3 - New Constraints: Ropes, Rods & Springs!
Major Release.
- Checks to prevent division by 0.
- Fix
Constraint:SetLength()
. Disregard invalid lengths. (length <= 0) - Fix
Engine:CreateConstraint()
. Disregard invalid thickness and lengths. (length & thickness <= 0) - Added new methods to
Constraint
Constraint:SetSpringConstant(k: number)
Constraint:GetId()
- New "type" paramater to
Engine:CreateConstraint()
- New "restLength" parameter to
Engine:CreateConstraint()
Engine:CreateConstraint(Type: string, point1: Point, point2: Point, visible: boolean, thickness: number, restLength: number)
- Added rope constraint type
- Constraints that have an upper constrain limit and exclusive of a lower limit. Similar to Roblox's 3D Rope Constraints.
- Added rod constraint type
- These constraints are similar to how Rope constraints function. But unlike rope constraints, these constraints have a fixed amount of space between its points and aren't flexible. These constraints can move in all directions just how rope constraints can, but the space between them remains constant.
- Added spring constraint type
- Spring constraints are elastic, wonky and flexible. Perfect for various simulations that require springs. Achieved using Hooke's Law.
- Type parameter in Engine:CreateConstraint() must be "SPRING", "ROD" or "ROPE" (text case does not matter).
Previously
- Added state management for RigidBodies. Individual RigidBodies can have their own States/Custom Properties now!
RigidBody:SetState(state: string, value: any)
RigidBody:GetState(state: string)
- Add type definitions & annotations
- Type check everything (almost)
- Removed code redundancies
- Replaced deprecations
Vector2.x
→Vector2.X
Vector2.y
→Vector2.Y
Vector2.magnitude
→Vector2.Magnitude
Vector2.unit
→Vector2.Unit
- … etc
Improvements to Code
Improvements to Code
- Add type definitions & annotations
- Type check everything (almost)
- Remove code redundancies
- Replace deprecations
Vector2.x
->Vector2.X
Vector2.y
->Vector2.Y
Vector2.magnitude
->Vector2.Magnitude
Vector2.unit
->Vector2.Unit
- ... etc
State Management
State Management
Added state management for RigidBodies. Individual RigidBodies can have their own States/Custom Properties now!
RigidBody:SetState(state: string, value: any)
RigidBody:GetState(state: string)
Example usage:
local Body = Engine:CreateRigidBody(frame, true, false)
Body:SetState("Health", 100)
local Killbrick = Engine:CreateRigidBody(frame2, true, true)
Killbrick.Touched:Connect(function(bodyID)
if Body:GetId() == bodyID then
local oldHealth = Body:GetState("Health")
Body:SetState("Health", oldHealth - 1)
return
end
end)
Quadtrees in Collision Detection!
Quadtrees in Collision Detection!
Quadtrees have now been implemented into the collision detection algorithm making the engine 10 times faster than before. Instead of wasting resources on wasted and unnecessary collision detection checks, RigidBodies are now distributed into different regions of a quadtree with a collision hit range. RigidBodies only in this hit range are processed with collision detection checks. This opens the gate for many new creations that required a larger amount of RigidBodies to be simulated!
Since Quadtrees are still in beta, there may occur bugs and unwanted behavior. If you encounter any, be sure to open an issue at the github repository. I'll be adding configuration methods for you to switch between traditional methods of collision detection or quadtrees.
Quadtrees in the works!
Quadtrees in the works!
- Collision Detection is now being re-written, with the addition of quadtrees!
- Fixed
RigidBody:Destroy()
Connections are now destroyed whenRigidBody:Destroy()
is called. - Added new methods to Points
Point:Velocity()
- Added new methods to RigidBodies
RigidBody:AverageVelocity()
- Added new methods to Constraints
Constraint:GetPoints()
Constraint:GetFrame()
- Fixed
Constraint:Destroy()
. Does not spam errors if connected to a RigidBody now.
Additions to Constraints, Engine and RigidBodies.
Additions to Constraints, Engine and RigidBodies.
- Added new methods to Constraints
Constraint:SetLength()
- Documentation
- Added new methods to RigidBodies
RigidBody:IsInBounds()
- Documentation
- 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)
Fixes and New Stuff!
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.
- Added new methods to Engine
- Engine:GetCurrentCanvas() - Documentation
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.