box2d-netstandard icon indicating copy to clipboard operation
box2d-netstandard copied to clipboard

[Bug] Prismatic Joint affected by Vector2.Normalize

Open BinarySpike opened this issue 1 year ago • 1 comments

Description

When applying a Prismatic Joint, the localAxisA is normalized. This causes {NaN, NaN} when the joint is new Vector2(0,0)

See https://github.com/codingben/box2d-netstandard/blob/b34d6238011a97a4f777e88dc41aa31f6b984c7b/src/box2dx/Box2D.NetStandard/Dynamics/Joints/Prismatic/PrismaticJoint.cs#L146

How To Reproduce

Create a new prismatic joint where the localAxisA is new Vector2(0,0)

You can work around the issue by using Reflection to update the private values:

var jdef = new PrismaticJointDef();
jdef.bodyA = body1;
jdef.bodyB = body2;
jdef.collideConnected = false;
jdef.localAxisA = new Vector2(0, 0);

var pJoint = world.CreateJoint(jdef);

var propX = pJoint.GetType().GetField("m_localXAxisA", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var propY = pJoint.GetType().GetField("m_localYAxisA", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
propX.SetValue(pJoint, new Vector2(0, 0));
propY.SetValue(pJoint, new Vector2(0, 0));

Expected Behavior

Something similar to:

https://github.com/erincatto/box2d/blob/c6cc3646d1701ab3c0750ef397d2d68fc6dbcff2/src/dynamics/b2_prismatic_joint.cpp#L88

BinarySpike avatar Oct 20 '22 04:10 BinarySpike