A couple of C# coding questions.

Hi I’m curious about in this line of code,

transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping);

why is rotation needed after transform.rotation,?

also, is if (Input.GetButtonDown())
the left mouse button by default- the same as if (Input.GetMouseButtonDown(0))?

In Quaternion.Slerp method, first parameter is the value you will want to change, and second parameter is the value to which you want to Slerp it to. So basically every frame you “Slerp” from transform.rotation (current value) to rotation (target value). It would be best to rename rotation variable to something like targetRotation to avoid confusion for beginners.

As for second question, no it’s not the same. Input.GetButtonDown() is used for Keyboard buttons and GetMouseButtonDown() is used for all moiuse buttons.

1 Like

Not entirely correct. GetButtonDown is used for getting the input from Unity’s input manager, which is works for different controllers. FE. GetButtonDown(“Fire1”) could be set up as either a keyboard button, mouse button or xBox controller button, etc.
But yeah, GetMouseButtonDown is indeed only for mouse buttons.

You’re right, my bad. I mistook GetButtonDown for GetKeyDown. GetKeyDown is the one that takes KeyCode enumerator as parameter. For example: Input.GetKeyDown(KeyCode.LeftControl);

Well honestly, while not configurable due to the mentioned enums, GetKeyDown also accepts mouse and controller input.

Thanks for helping clear that up. I think I get it a little better now.:slight_smile: