- Home /
Trying to understand directional calculations
I have this block of running in a FixedUpdate. Can anyone explain what this code is doing? I have already done some poking around on google but all of the explanations I am finding are difficult to understand.
if(currentDegrees != previousDegrees)
{
previousDegrees = currentDegrees;
tan = Mathf.Tan(Mathf.Deg2Rad * currentDegrees);
}
Vector3 pitchDirection = (centralControlHub.staticTiltShip) ? -playerShipRigidbody.velocity: playerShipRigidbody.velocity;
pitchDirection += Vector3.forward / tan * centralControlHub.staticPlayerShipMovementSpeed;
transform.LookAt(transform.position + pitchDirection);
tan is only Tan calculated when there's a change in degrees. pitchDirection is then either negative or positive ship velocity. The Syntax uses the Ternary operator a shorthand if statement. Finally, pitchDirection gets an additional vector added and the transform looks at where that vector ends relative to itself.
I understand that, I am more confused as to how $$anonymous$$athf.Tan() actually works and why it's useful.
I don't know in which context this is used, but to me it looks like what ever direction you're flying in, you always get corrected towards the world forward direction. Faster or slower.
Your answer
Follow this Question
Related Questions
CharacterController, Move toward mouse 1 Answer
Move Obj A towards Obj B BUT keep going in same direction when Obj A has reached Obj B 1 Answer
Moving a cube on the X-axis only moves by 1 unit? 1 Answer
2D Vector Movement,Vectorel Movement with Buttons 2 Answers
Controlling roll rotation when travelling along bezier curves 1 Answer