I want to create a character control similar to that of Dungeon Defenders: movement left right and forward/backward is the w,a,s,d keys - but rotation/turning is done with the mouse. My first instinct was to look at the mouselook script which comes with Unity for any code I could salvage. I’m pretty much brand new to programming and so understanding this script is a real challenge - it doesn’t help that there are no comments within the code’s body.
Things that I don’t understand:
- float rotationX = transform.localEulerAngles.y + Input.GetAxis(“Mouse X”) * sensitivityX;
Transform.LocalEulerAngles is described by the Unity API as: ‘The rotation as Euler angles in degrees relative to the parent transform’s rotation.’ What is the parent transform’s rotation? And why am I ADDING the mouse input along the x axis to this but focusing on the y axis with regards to the parent transform’s y ‘rotation’?
- ‘rotationY += Input.GetAxis(“Mouse Y”) * sensitivityY;’
Why do I use +=? Don’t get me wrong, I know what it means, rotationY = rotationY + Input.GetAxis(“Mouse Y”) etc. What’s the point in setting it equal to itself here if it’s an empty variable? Why do I need to plus two of the same variables together here?
I don’t want to bog you guys down with everything I don’t understand, those two appear to be the toughest concepts for me to grasp. As a matter of preference, please do not link me video tutorials. I’d like your own personal take on the issue if at all possible.
Thank you so much to anyone who can help.
Thank you :)
– putlucky