- Home /
how do i compare the angles of a rigid bodies velocity against its transform in one local axis
making a simple gliding game I'm pretty new to coding so I'm trying something simple ;) and i struggle with rotations so...
how would i compare the angle of a transforms rotation against its velocity in a single axis
so far i have this:
void Update () {
//get direction of travel rotation
rotateTowards = Quaternion.LookRotation(rigidbody.velocity);
//compare angles to transform
float AngleOfAttack = Quaternion.Angle(transform.rotation, rotateTowards);
}
but this gives me a value thats not very useful as i need the difference between the transform and the velocity in the transforms local X and Y axis separately so that i can add torques to rotate the rigid body to face the direction of travel
can i do this using vectors instead?
ok so still struggling with this…
managed to get the glider to rotate towards the direction of travel using:
float rotationTarget = Quaternion.LookRotation(rigidbody.velocity);
float actualSpeed = (rigidbody.velocity.magnitude * speed);
float step = (actualSpeed) * Time.deltaTime;
if ((AngleOfAttack > AOARotateTolerence) && (actualSpeed > speedRotateTolerence))
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationTarget, step);
but this doesn't give me any usable data like how far off is the direction of travel from the transforms Z axis in angle around x for example
Your answer
Follow this Question
Related Questions
Calculating Torque but cant add Quaternion 0 Answers
How to get rigidbody local z axis rotation in Euler angles? 0 Answers
look at movedirection 1 Answer
Rotation based on Velocity returning 0,0,0 rotation 1 Answer
Orbit cam and Rigidbodies aiming 0 Answers