A new project! 3rd Person Shooter needs a 3rd Person Camera!

Although one of my previous projects had been a 3D project, that game used static virtual cameras that would switch on triggers.

This time however I made a 3rd person camera that is controlled by the mouse! Now this isn’t quite right at the moment but we will get to that!

With our player able to move freely, lets take a look at the code!

Using Quaternions can be a little daunting just cause of the name but in reality it just stands for the rotation section of the transform component.

After setting our typical control GetAxis to float variables (this time our mouse movements), we then need to make sure that we can control our localEulerAngles(not world!) with them on each our mouseX and mouseY. It is flipped her due to the 3D so I am using mouseX for the y rotation and mouseY for the x rotation.

We can add a sensitivity variable as well so we can adjust the speed on the fly.

Lastly we set our local rotation to to a new rotation based on our respective mouse movement on the axis we choose. In the case of our currentRotation.y, Vector3.up represents the y-axis.

Repeat for the x axis (also while making sure to clamp the distance for this case).

After childing the Main Camera to the Player… we have a working camera look system that will actually rotate our Player as well!

The biggest thing is that we have to make sure both our movements for both the rotation changes are LOCAL.

We also need to make our Player move in LOCAL space as well by making sure our velocity uses the following code. With this our Player using the Unity Character Controller will move in the direction they are rotated in!

With all this put together…

I have successfully created a proper 3rd person movement system! Phew!

This project will just be a prototype so it may not take too long, however I am definitely going to be learning quite a bit through it.

See you next post!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Terraforming Load Balanced Multi-Region Hyperledger Besu Nodes on Azure

My Journey to Softw

Solidity Resources

Kubernetes Tutorial — A Comprehensive Guide The Orchestration Giant

Getting Started with Squarespace CSS

Breaking news Crodo

IoT: Respect the Present and Build for the Future

Walls, and breakthroughs. Please don’t give up!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Edward Kim

Edward Kim

More from Medium

Enemies Straight Ahead!

First! Unity.

Rethinking the Relationship in Mädchen in Uniform

My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt2