Question by
appnori · Jan 18, 2019 at 06:43 AM ·
rotationphysicsangularvelocity
how to calculate rotation
I have a problem that I cannot use the rigidbody. When the ball rotates with angular velocity, you have to calculate routing. I'm stuck here.
Rigidbody rigid;
public Vector3 startVelo;
public Vector3 startAngularVelo;
public Vector3 startForce;
// Start is called before the first frame update
Quaternion preRot;
Vector3 prePos;
Quaternion oldRot;
void Start()
{
rigid = GetComponent<Rigidbody>();
rigid.maxAngularVelocity = 1000.0f;
rigid.velocity = startVelo;
rigid.angularVelocity = startAngularVelo;
preRot = transform.rotation;
oldRot = new Quaternion(0f, 0f, 0f, 1f);
}
private void FixedUpdate()
{
Quaternion deltaRotation = transform.rotation * Quaternion.Inverse(preRot);
preRot = transform.rotation;
float angle = 0.0f;
Vector3 axis = Vector3.zero;
deltaRotation.ToAngleAxis(out angle, out axis);
angle *= Mathf.Deg2Rad;
Vector3 angluarVelo = axis * angle * (1.0f / Time.deltaTime);
Quaternion rotation = Quaternion.AngleAxis(angluarVelo.magnitude * Time.deltaTime, angluarVelo) * oldRot;
oldRot = rotation;
}
The value of oldRot and transform.rotation is different. Do you know why?
I am sorry for my poor English. Please help me.
Comment