Posted by jujunosuke
on 04 October 2012 - 08:24 PM
About suspension and weight transfer, i don't know if the solution i used can help any of you guys.
It is just a simplification of the concept, but honestly, i got pretty decent result and my simulation got better.
As kunos said, i use physX as my physics engine, with 5 rigid body connected with joints.
Basically i calculate the spring compression based on the distance of center of my wheel to the distance of my spring attached to the body of the car.
You can decide about the spring distance free height. I set mine to 0.36 meters.
That mean, if the car body is 0 kg the spring should not be compressed and give you 0.36 meters.
Then i just do some calculation of the distance. Vector3 of the center of the wheel, Vector3 of the joint position.
I then make calculation to get a result between 0 and 1.
0 mean that the spring is stretched to the max and give 0 grip. (spring free height)
1 mean that the spring is compressed to the max and give 100 % of grip.
once you made that, calculate the total force that your tire should provide and multiply it by the result of the spring compression.
Works decently for me and was really simple to implement.
But of course, this technique is valuable only if you use a 3d physics engine as mentioned.
I don't know what kunos think about this way of doing though..
This time, i am having trouble to find the Lateral Axis orientation on my aircraft. I am very surprise because i apply exactly the same technique as the longitudinal axis so i don't know what is wrong.
Here is how i proceed to find the Angle of my aircraft in comparison with the earth lateral axis.
var aircraftLateralAxis:Vector3D = aircraft.transform.right;
var worldLateralAxis:Vector3D = aircraft.transform.right.copy();
worldLateralAxis.y = 0;
var dotProduct:Number = aircraftLateralAxis.dot( worldLateralAxis );
var resultAngle:Number = Math.acos( dotProduct );
return resultAngle / Math.PI * 180;
If my longitudinal axis is 0, it works perfectly. But the more i increase the longitudinal axis (pitch rotation) and the more the lateral rotation look strange. (very hard to explain, so look at the demo)
So, in response to the help you received, why not help others by posting the solution?
You are right, but the solution is exactly what you wrote in the second message.
Anyway, here is the final code for those who are interested :
In fact after searching in the 3dEngine documentation, the transform.forward vector had an error in the code. So i looked at the last update and the correct version was updated. (Flash 3D Engines are very good but still very young).
var aircraftLongitudinalVector:Number3D = aircraft.transform.forward;
var worldLongitudinalVector:Number3D = new Number3D();
worldLongitudinalVector.clone( aircraftLongitudinalVector ); // important to clone the vector here, otherwise "worldLongitudinalVector.y = 0" will override aircraftLongitudinalVector.
worldLongitudinalVector.y = 0;
//Normalize both vectors
//Create the dot product
var dotProduct:Number = aircraftLongitudinalVector.dot( worldLongitudinalVector );
return Math.acos( dotProduct ) * 180 / Math.PI ;// The basic angle is in radians, so * 180 / Math.PI transform it in degrees.
Hope this help. Thanks again for those who helped me. Regards.