v0.6.0 - Clone() for Custom Rigid Bodies
- RigidBody:Clone() now works for custom rigid bodies.
- Added structure parameter to RigidBody.new() to cache the rigid body’s structure for the future.
- Remove restrictions from RigidBody:Clone()
Wow, that’s incredible! With that upgrade, I’m sure you’ll get a lot of new users.
can you link the old collisionservice? I wanna take a look at the source code
Hi! Recently I’m working on a game engine using your module. However the current errors that the module shows are very hard to debug.
For example let’s use this error [Nature2D] Received an Invalid Object Property.
In this case it’s super hard to figure it out why did it error, what property caused it.
For most of the warnings, errors should also say what property/object caused it. In this case it could look something like this: [Nature2D] Received an Invalid Object Property; MyExample (string)!
This is a very important and needed change, so I’ll get this done in v0.6.1! Thank you for the feedback.
Engine:Create()
cc: @james_mc98
Iterations provide accurate calculations for more rigid and smoother physics. Constraint iterations are applied to Constraint:Constrain()
method. Constraint iterations are extremely useful of rod constraints and rope constraints. Constraint iterations do not work on spring constraints.
Collision iterations are used to provide accurate and rigid collision detection and resolution. By default both of these iterations are set to 1. Iterations can be in the range of 1-10 only. Collision iterations can be set only if quadtrees are being used in collision detection.
Keep in mind that the higher the number of iterations the more accurate results. But, having more iterations means you’ll have to sacrifice performance. The lesser the number of iterations, the better performance but we’ll have to sacrifice on accuracy. So be careful where you use them!
Recommended Iteration Amounts:
Constraint Iterations - 3
Collision Iterations - 4
Engine:SetConstraintIterations(iterations: number)
Engine:SetCollisionIterations(iterations: number)
Examples of me using iterations for more accurate physics for rigid bodies and constraints.
Here, a simulation of a few boxes. They very rarely clip into each other and act more rigid than before. Running at 3 Collision Iterations and 3 Constraint Iterations.
Similarly, a box suspended from a rope. See how the rope doesn’t let the rigid body go farther than a set distance at all and immediately pulls it in place? Running at 5 Constraint Iterations.
Nice job, however will you ever consider making this recommended for (2d) games?
Not currently. The library is still under heavy work (been in beta for 3 months). Once I’ve got everything functional + new features, this library will be ready for dedicated 2D games. Right now, it’s just out for you to fiddle around with! If you’re are fine with the features it currently has, then you may consider using it for a larger project.
RigidBody:CanRotate(canRotate: boolean)
- Determines if a rigid body can rotate after collisions or when forces are applied, extremely useful for creating platformer games, top-down games etc.Engine:SetPhysicalProperty("UniversalMass", 5)
cc: @james_mc98
Incase you’re wondering how rigid bodies act when their CanRotate property is set to false:
If you’re creating platformers, character controllers or top-down view games then this feature should be perfect for you!
Looks incredible! Nice work dude!
I’ve updated the documentation site w.r.t the last 4 versions/updates. Edited a few code examples. Edited a few tutorials as well. I also wrote a new and short tutorial which deals with Engine Iterations. You can check that out here: Engine Iterations | Nature2D
Working on rigid body manipulation support for custom rigid bodies i.e. resizable, repositionable, rotatable hexagons/triangles/other polygons! (For v0.6.5)
Progress:
Here’s a re-sizable triangle!
RigidBody:Rotate()
RigidBody:SetPosition()
RigidBody:Update()
and RigidBody:Anchor()
).RigidBody:SetScale()
method as an alternative to RigidBody:SetSize()
but only for custom rigid bodies.
RigidBody:SetScale(scale: number)
- The scale of the default size is 1. Passing in 2 as the scale will double the size of the custom rigid body, etc. Similar to how UDim’s scale property works.RigidBody:SetPosition()
now works with custom rigid bodies.RigidBody:Rotate()
now works with custom rigid bodies.RigidBody:SetSize()
. Earlier RigidBody:SetSize()
changed only the size of the GuiObject and not the point-constraint structure.RigidBody:SetPosition()
, RigidBody:SetScale()
and RigidBody:Rotate()
all in action at once on a custom rigid body (an irregular polygon)!
I’m delighted you made progress. They’re rather good.
Working on improving garbage collection in Nature2D. The library in its current state is highly prone to memory leaks due to how different Destroy() methods have been implemented and how GC’ing is dealt with. I’ll be using Janitor to solve these issues.
You can track the progress over at the github repository:
Linked Pull Request - #33
Implemented proper garbage collection in the library for the Engine and all its Physics Objects to reduce chances of memory leaks in key areas. All problems listed in #33 have been dealt with.
src/Utilities
Engine:Stop()
no longer destroys connections of the Engine (Updated, Started, Stopped, ObjectAdded, ObjectRemoved). It simply pauses the engine by disconnecting the primary RenderStepped connection.Engine:Destroy()
- Disconnects all events, destroys all rigid bodies, points and constraints and also makes the engine unusable.Point:Destroy()
- Destroys the point’s GuiObject, destroys the point’s parent constraint (if any), and is no longer part of the engine.Constraint:Destroy()
- Destroys the constrain’t GuiObject, destroys the constraint’s parent rigid body (if any), destroys its points (point1 and point2), and is no longer part of the engine.RigidBody:Destroy()
- Destroys all events (Touched, TouchEnded, CanvasEdgeTouched), destroys its GuiObject, destroys its constraints (edges) which subsequently destroys all its points (vertices), and is no longer part of the engine.Instance:Destroy()
will trigger RigidBody:Destroy()
.Constraint:Destroy()
will trigger RigidBody:Destroy()
.Point:Destroy()
will trigger RigidBody:Destroy()
.RigidBody:Destroy()
's keepFrame: boolean
parameter no longer determines if the GuiObject of the rigid body is destroyed when the method is called. Passing it in as true will still end up destroying the GuiObject.Plugins.MouseConstraint()
will not function properly due to the introduction of Point:Destroy().These bugs shall be fixed in v0.7.1 along with bug #37.