Skip to main content

Engine Iterations

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!

You can set constraint iterations and collision iterations by using Engine:SetConstraintIterations() and Engine:SetCollisionIterations().

local Engine = Nature2D.init(someScreenGuiInstance)
Engine:UseQuadtrees(true)
Engine:SetCollisionIterations(2)
Engine:SetConstraintIterations(3)
Recommended Iteration Amounts

Constraint Iterations - 3
Collision Iterations - 4