Hi everyone, I was building a third person shooter game and found it to be difficult, I thought boy this process should be easier for everyone here. Since you guys are so very helpful to me on the forums I thought I would give some more back to everyone ![]()
I present to you a third person shooter source!
Controls:
Tab - Toggle Mouse
W - Forward
S - Back
A - Left
D - Right
Space - Jump
MWSWHEELUP - Zoom inn
MWSWHEELDOWN - Zoom out
Mouse Button One - Shoot
It is a basic scene that has a working third person look, with movement and when you look up it will follow the terrain and not go under it, it will also move the camera inn if anything is obscuring the aimer.
The bullets can be instantiated from anywhere and it will always fire bullets to where you aim even if aiming at the sky or off the terrain!
Break Down:
If we take a look at Player object there isnt much going on its a simple character controller and script. If you look deeper into its children, this is where the magic happens.
Shooting Point Object is where the bullets are made, it has a simple script that checks if you press mouse one then raycasts from pivot point (where you are aiming) and then it grabs the position of where the raycast hits and then it looks at that point so your bullets will always go where you aimer is looking.
It then instantiates a bullet and gives it a speed. You can move this object to anywhere you want. If you want it at the tip of your gun barrel just place it there in your 3d scene simple as that! This script also draws the crosshair, this is independent of where you place the object, the crosshair will always stay in the middle of the screen.
PlayerMesh object is just the character mesh.
RayCastBox is a box that stays infront of the camera so if you are looking at the sky you will always have something to raycast to.
PivotPoint Object has a script called mouselook, this controls your up and down look. You can move this around in the scene editor to have the crosshair anywhere you want (Over head) or (Over the Shoulder), really anywhere you want!
Its Child the Main Camera has a script called CameraBehave, this positions your camera a certain distance behind the camera and allows for zooming inn and camera placement so nothing obscures your view.
Anyway I hope I covered everything and I hope you like it.
TERMS OF USE:
You may use this in commercial and non commercial games only.
You may not resell this or claim it as your own.
If any improvements are made to the setup or source repost in this topic to better the third person shooter source for the community.
Special thanks to the people who posted the lovely code in the WOW Camera post.
I hope this simplifies third person shooters for everyone!
371025–12858–$thirdpersonshooter_178.zip (1.85 MB)