Hi !
I have a problem finding the correct axis of my hingejoints at runtime.
I Use them on the wheels of a Mars rover.
They always have to be perpendicular to the moving direction of course,
So I tried changing them but I cant make out the right way to do it.
I tried alot including TransformDirection, subtract from localRotation… to involve the transform.roots orientation, but didnt quite made it.
Can anybody help me wrapping my mind around this ?
I know theres also the Wheelcollider which can rotate along the y axis,
But its not really what im looking for.
void ApplyTorque (Vector2 moveVec) {
Vector3 steeringVec = new Vector3(moveVec.x, 0 ,moveVec.y);
Vector3 axisVec = -Vector3.Cross(steeringVec, transform.root.up);
hj.axis = axisVec; //smart people, assemble here !
Debug.DrawRay(transform.position, axisVec.normalized*8, Color.green);
Debug.DrawRay(transform.position, steeringVec.normalized*8, Color.yellow);
}
As you can see, the hingejoint axis (small orange arrows)
are off compared to the correct axis (green).
yellow rays are the moving direction.