HI, I have a question about the code used in the Project Boost lesson:
Ben suggests to use “(-Vector3.Forward);”
to project the booster in the opposite direction (whether you use Key A or D).
What I understand is that it is also possible to use “Back” as the obvious opposition to “Forward.”
I did this by mistake as I had paused the video before seeing Ben include the minus behind Vector3.Forward. For my brain, it made sense to use “Back” and it worked the same.
My question is (because I am new to Unity and Programming) should this give the same results in the future? Or by changing this (Opposed to Ben’s suggestion of
“-Vector3.Forward” give different results or bugs down the line?
I know there are many different ways to do the same thing, but I am curious what a more professional programmer has to say about this (just for my future understanding). I appreciate Ben and his courses and of course this site as well.
Learning lots and enjoying myself along the way!
Thank you
if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddRelativeForce(Vector3.up);
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.back); // (-Vector3.Forward); should be same function
}
else if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward);