Realistic FPS Prefab [RELEASED]

The Realistic FPS Prefab is an easy way to implement the core features of first person games into your Unity projects with a few mouse clicks. Set up is quick and just requires dragging and dropping the FPS object into your scene and assigning a layer to collision geometry. The asset has been designed with a focus on keeping scripts simple and ensuring that motion and effects are smooth and glitch free. The Realistic FPS Prefab is a great learning tool and template for FPS games.

What features does the Realistic FPS Prefab offer?
Full physics interaction with a rigidbody character controller that has mass in the game world. Pick up and throw objects, ride elevators and horizontal platforms, create physics puzzles, and climb ladders.

Player state handling for sprinting, crouching, and jumping movement states with seamless transitions, easily configurable speeds, and air manipulation. Player health management with damage from falling, enemy fire, and elevators is also included.

Advanced weapon positioning using sine bobs, iron sights, weapon sway, position changes based on player movement state, and animation for actions like reloading and readying weapons.

Camera movement effects such as weapon fire, landing, and pain kicks, as well as camera view animation to accompany weapon actions like reloading. Fully configurable sine bobbing based on player movement states is also supported.

Weapon behavior customization allows switchable auto and semi auto modes, shotguns, scoped weapons, accuracy handling, single shell reloading, and melee weapons by modifying the variables of one script instance from the editor - no additional scripting required to make a new weapon.

Item pickups to place in your scene for ammo, health, and weapons that can either be static or moveable (and throwable) rigidbodies.

Weapon effects like bullet impacts, smoke, tracers, and ejecting casings with simple variables to control size, velocity, and ejection delay of shells.

Ease of use through extensive documentation and commented code, simple drag and drop functionality of game objects into scenes, compatibility with version 3.5 and higher of Unity free and professional, and customization variables accessible from the inspector.

An example sandbox scene with an improved default AI for testing.

10 Likes

Hi, that looks good, nice asset.
1- The one thing I felt missing was the typical 'Q and E on keyboard to peek/see around corner.
2- Any part of your code u think it won’t be compatible with iOS?
3- Will u be adding touch-control for mobile devices from out of the box compatibility?
4- guns currently used in your web demo, are they included in the asset and ok to use for our own games?

Thanks

Thanks ProjectOne, Q and E leaning is a good idea and I’ll add it to the list of upcoming features.

This asset was developed with a focus on the desktop platform and IOS compatibility hasn’t been tested as I don’t have access to the licenses, but we have tested for functionality and framerate independence on a variety of desktop systems with success. As far as I know, the only part of the code that would affect performance on slower hardware is the fixed time step value, which is set to 0.01 (100 FPS) for smoother physics instead of the Unity default 0.02 (50 FPS).

On an Intel 1.8GHz dual core, there hasn’t been a noticeable decrease in performance, but a 0.02 fixedDeltaTime value could be used for mobile development. The rigidbody movements won’t be as smooth and the push forces would have to be lowered, but all runs well using both 0.01 and 0.02 fixedDeltaTime values.

Ideally, the asset would use the default 0.02 fixedDeltaTime, but ragdolls and rigidbodies that have their parents modified during runtime seem to loose their interpolation. Still looking into whether it is my code or a quirk in how the physics are calculated In Unity. A decrease in the fixed time step might not even be noticeable on smaller screens.

The only other issue I can think of would be if Unity has to use lower precision floating points on mobile. If the player travels 1000 or -1000 units from the origin, positional inaccuracies (spatial jitter) start to show up. I’m looking into a fix for this, which involves moving all objects back to the origin, but it isn’t high priority because 2000² units is a decent amount of room to work with.

These pages describe the topic pretty well:

http://pompidev.net/2012/12/21/3d-graphics-quality-and-floating-point-accuracy-on-android/

http://answers.unity3d.com/questions/54739/any-solution-for-extreamly-large-gameworlds-single.html

A simple work-around would just be to place the player at the origin or around a -500 x or y position and have them move into positive x and y values, but not exceeding the range that causes spatial jitter. Lower floating point precision might not even be an issue on mobile, but it’s something to be aware of.

As far as out of the box touch controls, it’s a possibility, but it wouldn’t be for a while because I don’t have a way to test code on mobile yet. The way player input is handled in this asset is fairly simple and I imagine it would just involve setting up the touch button/virtual pad code and piping it into the Input.GetKey references in the scripts. We are also available for support if you have any questions about how the input code works.

The gun models were put together using Creative Commons licensed models and animated by us, so they should be ok to use in your games.

Hope that answers your questions.

This looks really cool but I’d like to ask a few questions first before I buy it. Do you know if any of the scripts are compatible with Ultimate FPS Controller, such as your ladder scripts and you physics pick up? :slight_smile:

Curious as well.

Thank u for your clear reply Azuline. Good stuff

Thanks TheRealFuzz and lod3. The ladder script was designed to have the least amount of code as possible (for efficiency if there are a lot of ladders/climbing surfaces) and just sets a climbing boolean value in the character controller script to true or false. The character controller then uses the climbing value to determine when to add vertical climbing speed to the total player velocity.

So to add our asset’s ladder climbing the Ultimate FPS Camera, you would need to locate where total player velocity is calculated in the character controller and adapt the appropriate code there from our project. I’m not sure if the Ultimate FPS Camera uses a rigidbody character controller, but if it does, the rigidbody.velocity could be set to something like Vector3(velocity.x, climbSpeedAmt, velocity.z);

We could have made the ladder climbing script more self contained and portable without so much integration with the charater controller, but it wouldn’t be optimal if there are a lot of ladders in the scene whereas the character controller has just one instance in the scene and has access to other variables that affect player velocity.

On the other hand, the rigidbody dragging/physics pick up script is more portable and can be added to another character controller object with an attached rigidbody.

We’ve made a lot of effort organizing our code in a way that is easy to understand so that it can be modified and used as a learning tool for Unity. We are also available for support if you have questions.

Thanks for the reply! I think I may have to take a chance and grab this asset :slight_smile:

Also, any idea how compatible this is with networking?

Wow! this is pretty awesome! = ) I’ll need to get this one really soon. Good job! and Thank you for such a Great Asset! Only I would suggest maybe changing your Assets Category, I would think this goes under Complete Project / Template Category, instead of just Scripting. You may want to update this to ensure you get sales from people who are not on the forums and looking through that category for more complete assets like this one.

Questions… I see you include a bot with AI.

Does the AI use Path-finding (+navmesh), with a Node Grid setup or something? is does it work without these…?

and finally can you somehow tweak the include AI to work for Zombie’s that do Close Range Damage, instead of Long Ranged (since zombies don’t shoot lol!) please do let me know.

So I bought it and everything is working pretty well but I have a problem. When I use the rigid body grab script, when I drop objects they fall to the ground really slowly instead of fast.

Thank you TheRealFuzz, networking hasn’t been tested with this asset, but I assume that it would be compatible. I haven’t delved into networking with Unity yet and the only problem I can think of might be with the rigidbodies. A lot of physics calculations would mean higher latency, so if there was a way to selectively make some of the physics (like bullet shells and ragdolls) client side, networking would be faster.

For the rigidbody falling problem, are you using a new scene, or is this happening in the included sandbox scene? You might want to check that your gravity setting in Edit->Project Settings->Physics is set to something like 0, -9.8, 0. Also, on the rigidbody component of the object you are dropping, is the drag value set to something high like over 0.6 or so? Or is the rigidbody’s mass set to a very low value? You might also want to check if the fixed timestep value in Edit->Project Settings->Time is anything other than 0.01 or 0.02 when running the scene in the editor.

Either one of those could cause slow rigidbody falling. If you are still experiencing the issue could you please post, email, or PM me with specific details about what happens when you try to drop the rigidbody, like if you are running the scene in the editor or standalone, if there any printed errors, or unexpected movements of objects? I appreciate the feedback TheRealFuzz!

Kurato, this asset does seem to be more of a complete project/template , I’ll have to change the asset category for the next update :slight_smile:

The included AI doesn’t use pathfinding or Unity’s navmesh. The main focus of this project is FPS player mechanics, so the AI is there just for testing at the moment. The next step to improving the AI would be to either use Unity’s navmesh or incorporate a third-party pathfinding solution like simple path. An option to have the AIs select random points to wander to would also be a good addition.

The current AI uses waypoints that define a patrol path which they follow until they see the player. If the Do Patrol check box of the AI.js script is not clicked, they simply stand watch until they see the player. When the player is in view, they run after the player and attack, but once their line of sight is blocked, they walk back to their patrol path or original position.

To turn the current enemies into melee attacking zombies, you first need to change the Shoot Range and Dont Come Closer Range values in the AI.js script instance of the enemy object to 2.

In the next update, that’s all that you’ll need to do, but the current version, you also need to change the AI.js script starting at line 113 from:

			if(distance > shootRange * 3){
				speedAmt = 1.0f;
				return;
			}

to

			if(distance > attackRangeAmt){
				speedAmt = 1.0f;
				return;
			}

And the enemy will run up close before they start attacking. The Attack Range value determines at what range they will see the player and start attacking. Maybe I will include melee enemies in a future update, all that’s needed is a zombie model with a melee attack animation and a different sound effect.

Thanks for getting back to me. I just tested the example that came with this asset and I can confirm that objects slowly fall down in the example scene. I’ve check all the values that you’ve suggested and still no luck, I’ll keep searching and see if I can fix it.

I see what the problem is now. The Drag Rigidbody script increases the drag of an object when you pick it up so it won’t spin around excessively when you move the mouse. The script usually changes the drag back to it’s original value, but for some reason it’s missing that step, or overwriting the original drag value and the object is keeping the high drag value (10 by default). I’ve never seen this happen until I was working on something else with this script. Really sorry about this. I’ve checked for, and fixed all the problems I could find, but this is one of those bugs that is hard to track down because it shows up somewhat randomly. I’ll let you know once I find a fix, so you won’t have to wait for the update.

Thank you very much! Looking forward to it :slight_smile:

No problem, thank you for letting me know about the issue!

Ok this should fix two bugs in the DragRigidbody.cs script. The next update will include these fixes, but you can apply them now if you want. Be sure to back up the original DragRigidbody.cs script before making these changes in case you make a mistake. It’s also important to follow these steps in the order they are posted because I will be referring to line numbers.

First, around line 16 change:

private	float oldDrag;
private float oldAngularDrag;
	
void Update (){

to:

private float oldDrag;
private float oldAngularDrag;
private bool dragState;
	
void FixedUpdate (){

then, around line 27, change:

	RaycastHit hit;
	if(!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, reachDistance)){
		return;
	}

to:

	RaycastHit hit;
	if(!Physics.Raycast(Camera.main.transform.position, ((Camera.main.transform.position + Camera.main.transform.forward * reachDistance) - Camera.main.transform.position).normalized, out hit, reachDistance)){
		return;
	}

then, around line 61 change:

IEnumerator DragObject ( float distance  ){
	oldDrag = springJoint.connectedBody.drag;
	oldAngularDrag = springJoint.connectedBody.angularDrag;
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;

to:

IEnumerator DragObject ( float distance  ){
	if(!dragState){
		oldDrag = springJoint.connectedBody.drag;
		oldAngularDrag = springJoint.connectedBody.angularDrag;
		dragState = true;
	}
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;

then, around line 69 change:

		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		springJoint.transform.position = ray.GetPoint(distance);
		if(!Input.GetKey(KeyCode.X)){

to:

		Ray ray = new Ray (Camera.main.transform.position, ((Camera.main.transform.position + Camera.main.transform.forward * reachDistance) - Camera.main.transform.position).normalized);
		springJoint.transform.position = ray.GetPoint(distance);
		if(!Input.GetKey(KeyCode.X)){

and finally, around line 107 change:

	springJoint.connectedBody.angularDrag = oldAngularDrag;
	springJoint.connectedBody = null;

to:

	springJoint.connectedBody.angularDrag = oldAngularDrag;
	springJoint.connectedBody = null;
	dragState = false;

If all went well, the script should compile and you should be able to start the scene in the editor and be able to drag rigidbodies without needing to left click outside the running game window and back in it again. This should also fix the rigidbody drag not being set to its original values when you let go of an object.

Also note that the first Raycast doesn’t use a layer mask and is checking all layers for hits. In the next update, this Raycast will be using a layermask. For efficiency it will only check objects that can be picked up. I excluded that part of the code to make this fix easier to apply.

If the rigidbodies are still falling slowly or the script doesn’t work, please copy the backup DragRigidbody.cs back over your modified script, and let me know so I can keep looking at the code, but I’m pretty sure this solves both problems.

Thanks for going to all the trouble but I couldn’t get the script to work but I’m sure it works on your end, as you can probably tell, I’m not much of a coder :stuck_out_tongue:

Would it be to much to ask for you to PM me the edited script? Otherwise I can wait for the next update.

hey Azuline, I just purchased this Asset on Saturday! I was as impressed with it as I was when i saw the demo and asset features. Really Awesome man! One of my best Asset purchases to Date I must say. THANK YOU! for the above fix to turn the AI into Melee Attacking Zombies! = )

I have a game called ZombieWarz… http://zombiewarz.com that uses Ultimate FPS Camera and a Zombie Asset, I was thinking of updating the Game using your Asset! So this Fix will be very helpful for me to at least get some Zombies in the game to see what it looks like… later I’ll try to update the AI unless you manage to update the AI before I do lol. = ) anyway thanks again! awesome job on this asset and support.

PM sent. Hope the updated script works better for you TheRealFuzz!

Thank you Kuroato! Really glad that you’ve been enjoying the asset. A lot of time and effort has been put into this project :slight_smile:

We’ll see about improving the AI, there are a few other features we’re looking at first though. The AI really only needs some pathfinding added to it. The enemies work surprising well for just having linear paths to their goals. They can get stuck behind walls sometimes, but I think it helps that they have round capsule colliders as it helps them get around corners. Best of luck on your project!

Is it possible to add your own guns?