Hello everyone!
I’m relatively new to Unity and I’ve been trying to learn as much as I can about scripting through YouTube but most people seem to have their own way of doing things, so it’s difficult to add the the things I’ve learned together, so I thought I’d come here.
What I’m hoping to do is make a first-person character controller in C#. The game I’m making makes it difficult to just use the ones found in the Standard Assets package because I seem to need multiple scripts just to do simple things and it just feels sloppy. I would like to have a “Leg” object that controls forward/backward/turning movement, a “Torso” object that rotates on the y-axis, and a “Head/Camera” object that rotates on the x-axis.
What I’m guessing I need to do is reference the separate game objects in the script so that the “Torso” and “Head” stay “connected” to each other, so that the “Torso” and “Head” rotates relative to the “Legs” and “Torso,” respectively, and so that the “Head” faces the same x-direction as the “Torso” at all times, but the “Torso” doesn’t rotate along the x-axis with the “Head.” The best way to describe it would be a tank, with a separate chassis, turret, and barrel.
I’m also unsure about syntax. I know I’ll need transform.Translate, transform.Rotate, Vector3 (which controls direction?), and Time.deltaTime. I’m not sure how to add a sprint or crouch feature; is there a command to only increase speed when a key is being pressed and a command to toggle speed on/off, and could this also work to toggle the camera’s FOV for an aiming-down-sights mode? I’d also like to add a headbob feature so I would transform the camera’s position using cos(y) and sin(x)?
Thanks for any help in advance. I don’t expect anyone to write the script for me, I’d just like an overview of any commands I might need and the syntax required to run it in Unity.