THIRD PERSON SHOOTER SOURCE

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 :slight_smile:

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)

It didnt work for me. Its in a very old version of unity.

Imported assets end up screwed, cant even play anything.

Same here, I couldn’t open the scene or do anything.

Interesting, im actually running beta 6, that may be why. Is there anyway to correct this besides downloading and installing a non beta version of Unity and then uploading it again after saving it?

Ok I downloaded unity 2.6 and rebuilt the scene in there, saved and reuploaded, I even made it more simple by adding the Raycastbox to the pivot point so you now only have one cube. Please let me know if it works now thanks.

A very basic starting point, perhaps, but it worked fine for me. This could be handy to point someone in the right direction if they’re new to Unity and looking to make something similar.

I tested it and found it easy to use. thanks for this!

Its awesome, but how to i modify this to make the player NOT turn as the mouse turns?

In the script simpleFPSWalker.js there is these lines of code:

	//This is the heavy lifting part of the combat mode part and mouselook part
	if (toggleCombatMode == true )
	{
	rotationX += Input.GetAxis("Mouse X") * sensitivityX;
	}
	xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
	transform.localRotation = xQuaternion;

}

What basically is happening here is if the combat mode is true, that means the cursor is hidden and you can use mouselook then it will turn the character left and right. Modify this to get the effect you are looking for.

Thanks your camera behavior script really helped me out.

Thanks:) will put it to good use.:slight_smile:

thanks. Looking for a third person example. Good job. :slight_smile:

Edit: Anyways i love ur cameras. this is what i am finding for so long. Thanks, but i noticed something wrong with the bullets, when i press mouse 0, it keeps spawning bullets and the bullets keeps shooting from the sides. maybe cuz i upgraded the project. Thanks anyway.