How to set clockwise or counterclockwise rotation?
Hi all,
I'm working on a 2D game in which a spaceship automatically advances until it is close to a planet. On reaching the orbit of the planet the ship must decide whether to rotate clockwise or counterclockwise depending on the angle of arrival.
I have the position of the planet (closest), the position of the ship (transform) and the old position of the ship (previous) I would like to calculate the angle between these three points but do not get the desired result.
I have tried many things but I can not properly decide the direction of rotation. Can anybody help me?
Thank you very much!
//If spaceship is near to a planet --> orbit it
if (distance<rotationDistance) {
float deltaX = transform.position.x-previous_X;
float deltaY = transform.position.y-previous_Y;
float deltaZ = transform.position.z-previous_Z;
previous_X = transform.position.x;
previous_Y = transform.position.y;
previous_Z = transform.position.z;
Vector3 direction = new Vector3 (deltaX, deltaY, deltaZ);
Vector3 dir1 = (transform.position - closest.transform.position).normalized;
Vector3 dir2 = (direction - closest.transform.position.normalized);
angulodegiro = Vector3.Angle (dir1, dir2);
if (angulodegiro >0) {
giro = "clockwise";
} else {
giro = "counter-clockwise";
}
}
Your answer
Follow this Question
Related Questions
Check rotation of an obstacle 0 Answers
Making an object spin on impact 0 Answers
With VR character's rotation is applied twice or double 1 Answer
Using LookAT causes no rotation at all? 1 Answer
rotation problems 0 Answers