Code Optimization
So basically my camera orbits around the player and you can rotate it using Q and E. So because Input.GetKey gives a boolean value I have to use if statements and basically have a temporary variable that get a float value if GetKey is true. Then angle is changed according. I was hoping there was some way to optimize this maybe 2-3 lines. You can ignore the last line really.
if (Input.GetKey(KeyCode.Q)) {
gotQ = orbitSpeed;
}
else {
gotQ = 0;
}
if (Input.GetKey(KeyCode.E)) {
gotE = orbitSpeed;
}
else {
gotE = 0;
}
angle = angle + gotQ - gotE;
transform.position = player.position + new Vector3(Mathf.Cos(angle) * distance, distance, Mathf.Sin(angle) * distance);
Answer by JedBeryll · Jun 16, 2017 at 04:23 AM
Well not much of an optimization but if you create an axis then you get a -1, 1 value so you can lose the "if"s. In that case it's just: angle = Input.GetAxis("Rotate") * orbitSpeed;
Then you can set the position.
Your answer
Follow this Question
Related Questions
Help rotating camera script 0 Answers
camera movement on a sphere 0 Answers
Help with third person shooter camera/character rotation (please :)) 0 Answers
How do I optimize my code?,How do I optimize my script? 1 Answer
Issue with getting the mouse position in 3D and moving a gameobject on the y & z axis 0 Answers