rotationThrust question

This post has 2 related questions.

  1. This question is not only related to rotationThrust, but any variable related to a created method.

When he used rotationThrust in the lecture video, he listed it as a variable, which is fine and dandy. However, he removed rotationThrust from the transform.Rotate(Vector3.forward * rotationThrust * Time.deltaTime); and replaced it with transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);

Since he created the method ApplyRotation(); BEFORE replacing rotationThrust with rotationThisFrame in:

transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);

does that mean that the newly created method of ApplyRotation(); still has:

transform.Rotate(Vector3.forward * rotationThrust * Time.deltaTime);

in the method created? or does the method created automatically update to have the rotationThisFrame in it?

I ask this because in many programs I have worked in outside of coding, updating the information in the method changes the method.

  1. He uses these terms such as mainThrust, rotationThisFrame, and other terms in the course that I cannot find when I search for them on the Unity Docs. Are these above terms official code terms, or is he creating these terms himself?

example: in theory, could I instead name the term mainThrust to mainThruster if I so chose? I ask because when in the future I go to look up code on Unity Docs, I want to make sure I’m entering the correct terms so that the code works properly and I can also understand what is written.

Hi NinskiGaming,

I’m not sure if I understood your questions correctly. Before I write confusing nonesense, let me state one important thing: In your code example, we do not pass on variables to the Rotate or whatever method. We pass on values.

If rotationThrust = 25.5f, we would actually pass on:
transform.Rotate(Vector3.forward * 25.5f * Time.deltaTime);

The same applies to Vector3.forward and Time.deltaTime. We do not pass on these names but the values.

For this reason, it does not matter how we named the parameter of the ApplyRotation or any other method. The program just looks at the “slots” and the type of the “slots” in the parentheses of the method. When the method gets called, argument 1 gets assigned to parameter 1, argument 2 gets assigned to parameter 2, and so on.

Regarding your second question, that’s a bit more difficult. C# itself consists of a few names and rules only. You could learn it within a couple of days. The complexity stems from the framework you use. In our case, we use Unity. The Unity programmers did the same what we do: They created classes and named their methods, variables and other things They created hundreds/thousands of classes. We don’t know all of them either, so we often check the Unity API, Unity manual and look for information elsewhere on the internet.

If you do not know if a name was introduced by the instructor or if it has already been there, hover your mouse over the name and read the information that pops up in your script editor. If the message mentions your own class (e. g. Rocket.rotationThrust), the name was introduced by you. If the message does not mention your class (e. g. UnityEngine.Rigidbody.transform), the name has already been there. Another indicator for your own variables is that you declared them in your code: Type variableName; or Type variableName = 123;.

In your own code, you may name your own things as you wish as long as the names are unambiguous.

If you enter the wrong name, the compiler will complain, so don’t worry too much about it. If you type a wrong name, the error message usually says that the name did not exist in the current context.

Is this what you wanted to know?


See also:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms