This is the code that i now use for the wheel attaching
If I have the wheel going in the direction of the x axis then it does this...
http://www.youtube.com/watch?v=ABWgSkOUcXM
If i rotate it in another direction it does the same bug as before where the rotation wraps over...
I am using the wheels matrix for calculating all the joints but still no luck
Heres the code i use.
//The entity the raycast has hit
Entity body = HitEntity;
Entity wheel = Bodys[0];
//My wheels are already rotated by the time we get to attaching them here so we must set the rotation of all the joint stuff
Matrix o = wheel.OrientationMatrix;
//Connect the wheel to the body.
var pointOnLineJoint = new PointOnLineJoint(body, wheel, wheel.CenterPosition, o.Down, wheel.CenterPosition);
var suspensionLimit = new LinearAxisLimit(body, wheel, wheel.CenterPosition, wheel.CenterPosition, o.Down, -1, 0);
//This linear axis motor will give the suspension its springiness by pushing the wheels outward.
var suspensionSpring = new LinearAxisMotor(body, wheel, wheel.CenterPosition, wheel.CenterPosition, o.Down);
suspensionSpring.Settings.Mode = MotorMode.Servomechanism;
suspensionSpring.Settings.Servo.Goal = 0;
suspensionSpring.Settings.Servo.SpringSettings.StiffnessConstant = 200;
suspensionSpring.Settings.Servo.SpringSettings.DampingConstant = 50;
var swivelHingeAngularJoint = new SwivelHingeAngularJoint(body, wheel, o.Up, o.Right);
//Motorize the wheel.
MyMotor = new RevoluteMotor(body, wheel, o.Left);
MyMotor.Settings.VelocityMotor.Softness = .2f;
MyMotor.IsActive = false;
MyServo = new RevoluteMotor(body, wheel, o.Up);
MyServo.Settings.Mode = MotorMode.Servomechanism;
MyServo.Basis.SetWorldAxes(o.Up, o.Right, o.Forward);
MyServo.TestAxis = body.OrientationMatrix.Right;
//Add the wheel and connection to the space.
space.Add(pointOnLineJoint);
space.Add(suspensionLimit);
space.Add(suspensionSpring);
space.Add(swivelHingeAngularJoint);
space.Add(MyMotor);
space.Add(MyServo);
Physics Accuracy Issues...
Re: Physics Accuracy Issues...
Consider the basis that my example used. If you assign the axes to your right hand, your thumb pointing up could be "Up" in the car's frame, the index finger pointing out would be "Right" in the car's frame, and your palm is facing "Forward" in the car's frame. This works for my example because of the local configuration of the wheels versus the body. Instead of using the car's frame, you can use the wheel's frame, but notice that the 'up' and 'right' etc. are different for the wheel.
To accommodate the wheel's different basis, you can change the axes that compose the constraint basis. Rotate your right hand 90 degrees to the left and see what axes are now in the constraint basis- it should be Up, Forward, and Left.
Instead of finger-fiddling, you can also just use matrix math. Rotating the matrix that you're getting the up/right/forward from by 90 degrees around the local Y axis would accomplish the same result.
Edit: Also remember that every single constraint- not just the steering motor- needs to handle it in the same way.
Edit 2: The actual transformation needed might not be 90 degrees around the Y axis, but it looks like it probably is (either + or - 90). I haven't actually examined/tested that chunk of code yet with changes to see.
To accommodate the wheel's different basis, you can change the axes that compose the constraint basis. Rotate your right hand 90 degrees to the left and see what axes are now in the constraint basis- it should be Up, Forward, and Left.
Instead of finger-fiddling, you can also just use matrix math. Rotating the matrix that you're getting the up/right/forward from by 90 degrees around the local Y axis would accomplish the same result.
Edit: Also remember that every single constraint- not just the steering motor- needs to handle it in the same way.
Edit 2: The actual transformation needed might not be 90 degrees around the Y axis, but it looks like it probably is (either + or - 90). I haven't actually examined/tested that chunk of code yet with changes to see.