matter-js
matter-js copied to clipboard
Angle constraints
Work in progress, this feature and API is subject to change.
Features
- builds on
Matter.Constraint
- distance or pin supported
- angles for one or both constraint points
- angle stiffness, angle-min and angle-max bounds
- global-relative angle for world points
- body-relative angle for body points
Usage
See the Angle Constraints example for usage. The new constraint properties are:
-
constraint.angleA
the target angle at point A (body-relative or world-relative depending on usage) (default0
or initial angle between points and x-axis) -
constraint.angleAMin
min bound, anti-clockwise relative toangleA
(radians, default0
) -
constraint.angleAMax
max bound, clockwise relative toangleA
(radians, default0
) -
constraint.angleAStiffness
the angle stiffness (0
to1
, default1
) -
constraint.angleB...
-
constraint.render.angles
boolean to render angles when usingMatter.Render
(defaulttrue
)
Angles are either relative to the body, or to the world (x-axis), depending on what the constraint is connected to. For example:
- if
constraint.bodyA
is set, thenconstraint.angleA
is relative to the body angle - if
constraint.pointA
is set, thenconstraint.angleA
is relative to the world
Requesting reviewers, testers and comments
If anybody has any time to help me test this update out further and feedback any issues and test cases, it would be greatly appreciated.
You can try out this feature by using the alpha build on this branch.
Known issues
- chains of angle constraints have issues
- some configurations can build up extra energy when moving around rapidly
- possibly a mouse constraint issue only
Breaking changes
- the original internal property
constraint.angleA
is nowconstraint.angleAPrev
(same for B)
Changes
- adds angle properties to
Matter.Constraint
objects - adds angle constraints example
- adds angle constraint solving to
Matter.Constraint
module - adds angle constraint rendering to
Matter.Render
- adds
Common.angleDiff
,Common.clampAngle
Awesome!!!
While trying this out I ran into a small problem, if I try to make a pin constraint (length=0, stiffness>0.1) constrained by angles, the debug renderer breaks in Render.constraints
as it's unable to draw a line to end.x, end.y
as end
is never set.
@Prokos good catch, I couldn't reproduce the issue as I'm not sure on the setup required for it but I've accounted for that
Hi @liabru is this one dead? What is missing? This would be a killer feature.
Gonna have to bump this. This allows for axels and pins which were previously missing