Modular First Person Player v1.0.2.7

MANUAL

Compatible with Unity 2017.3.0f3 and up

Table of Contents

1. What’s inside?
  1.1. Scripting & Behaviours
  1.2. Materials & Textures
  1.3. Meshes
  1.4. Prefabs
  1.5. Sounds
2. Code Documentation
3. Setup & Settings
  3.1. Player
    Main Settings
    Camera Extra Settings
    Control Settings
    Collision Settings
    Movement Settings
      Jump Settings
      Sprint Settings
      Crouch Settings
    Footstep Settings
  3.2. Footstep Asset
  3.3. Footstep Data
  3.4. Footstep Override
  3.5. Player update flow
4. Player Modules
  4.1. Adding a module
  4.2. Bob Module
  4.3. Pick Up Module
  4.4. Rigidbody Push Module
  4.5. Ladder Module
  4.6. Creating a module
5. Troubleshooting & Tips
  5.1. The Player goes right through rigidbodies sometimes
  5.2. Changing what the Player collides with
  5.3 My footsteps doesn’t work
6. Contact

1. What’s inside?

1.1. Scripting & Behaviours

1.2. Materials & Textures

1.3. Meshes

1.4. Prefabs

1.5. Sounds

2. Code Documentation

You can refer to MFPP’s code documentation directly through your IDE of choice with Intellisense or by going to the generated code documentation here.

The entirety of the code in this asset is documented as well as commented to understand the inner workings of it, as well as understanding on how to use it and expand it.

3. Setup & Settings

This section will walk you through how to setup the player controller provided in this asset, along with every of its settings. You can also open the example scenes located in Assets 🡲 MFPP 🡲 Scenes.

3.1. Player

The player controller already has a prefab ready for use and modification located in Assets 🡲 MFPP 🡲 Prefabs 🡲 Player.

In this prefab, you will have this script attached to the Player game-object. Alternatively, if you are creating a new game object to place the Player script on. You can find it under Add Component 🡲 Scripts 🡲 MFPP 🡲 Player.
 

If you are creating the player, do not forget to attach a Camera to it, like so:
 


(Make sure that the camera is parented to the player!)

Along with the Player script, you will also have a Character Controller attached to it automatically, as Player depends on it.
You can change a few settings on the Character Controller component, such as:

Remaining settings on the Character Controller component are controlled by the Player script.

You can also change all of the properties of the attached Camera just like any normal camera, the Player script only has control over the Transform of the camera.

Main Settings

Camera Extra Settings

Control Settings

Collision Settings

Movement Settings

Jump Settings
Sprint Settings
Crouch Settings

Footstep Settings

3.2. Footstep Asset

You can create a Footstep Asset by right-clicking in the Project window, Create 🡲 Footstep Asset.

There is also a Footstep Asset ready for use located at Assets 🡲 MFPP 🡲 Sounds 🡲 Example Footsteps
 

3.3. Footstep Data

This is where you will add your footsteps, jumping and landing sounds, along with linking them to specific surfaces, materials & textures.
 

3.4. Footstep Override

You can override the footstep data to use on a collider with the FootstepOverride script, useful when you want to exceptionally change the footsteps used for a material or texture that is already used, or you just don’t have any mesh-renderers and only the collider to work with.
 


In this example, we link this game-object to use the “Wood” footstep data in our FootstepAsset assigned to our player, just make sure that you have a footstep data with an existing name in order for it to work.

3.5. Player update flow

void Start()
Player initialization
Initialize player modules
void Update()
BeforeUpdate();
Call BeforeUpdate(); on all player modules
DoMouse();
DoMovement();
UpdateHeight();
DoMisc();
DoFootsteps();
AfterUpdate();
Call AfterUpdate(); on all player modules

(See 2.0. Code Documentation for more information)

4. Player Modules

With Player modules you can extend the functionality of the Player script however you would like.

4.1. Adding a module

Adding a module is easy and only requires adding the desired Player Module component in the game object where the Player script resides.
 

Any class that inherits from the PlayerModule class is a valid module.

4.2. Bob Module

Bobs the camera as we walk and land.

4.3. Pick Up Module

Pick up rigidbodies and carry them around.

4.4. Rigidbody Push Module

Pushes rigidbodies around as you attempt to walk through them.

4.5. Ladder Module

Allows you to climb on ladders.

The ladder climbing sounds takes the material of the ladder you’re climbing (Or default footsteps if none found), if you want special ladder sounds, create a Footstep Data in your desired Footstep Asset, assign it a name like “Ladder” and add the desired sounds to it.

(Do not forget to create an appropriate layer, like “Ladder”, and apply this layer to ladder game objects. You may need to create that layer and reassign it to the game object and this ladder module for the Example scene.)

4.6. Creating a module

In order to create your own module, you will need to create a script. Right-click on the Project window, Create 🡲 C# Script.

Go ahead and edit the script and change it all with the following:

using UnityEngine;
using MFPP;

public class NameOfYourModule : PlayerModule
{

}

This is the very base of a player module.

The PlayerModule base class contains a few overridable methods such as:

public virtual void Initialize();   // This is called whenever the player initializes all modules.
public virtual void BeforeUpdate(); // This is called before the update of the player.
public virtual void AfterUpdate();  // This is called after the update of the player.

You can also register events from the player, into the module, events such as:

Player.OnAired             // Called when the player just aired.
Player.OnLanded            // Called when the player just landed.
Player.OnFootstep          // Called when the player just emitted a footstep.
Player.BeforeFinalMovement // Called just before the final movement.
Player.AfterFinalMovement  // Called just after the final movement.
Player.CollisionDetected   // Called when a collision has been detected.

(For more information, check out 2. Code Documentation)

Let’s make a fun module, like jumping very very high when you press H.
We want a jumping power in the inspector, so let’s add that first.

public float JumpingPower = 50f;

Then we want that whenever we press H, we apply an upwards force times the jumping power supplied, but only when we are grounded.

public override void BeforeUpdate() // Run before the update of the player.
{
    if (Player.IsGrounded && Input.GetKeyDown(KeyCode.H)) // If grounded and we are pressing H.
    {
        Player.EmitJumpSound(); // Emit jumping sound.
        Player.AddImpulse(Vector3.up * JumpPower); // Add upwards jump impulse.
    }
}

You should end up with something like this:

using UnityEngine;
using MFPP;

public class HighJumpModule : PlayerModule
{
    public float JumpPower = 50f;

    public override void BeforeUpdate() // Run before the update of the player.
    {
        if (Player.IsGrounded && Input.GetKeyDown(KeyCode.H)) // If grounded and we are pressing H.
        {
            Player.EmitJumpSound(); // Emit jumping sound.
            Player.AddImpulse(Vector3.up * JumpPower); // Add upwards jump impulse.
        }
    }
}

And there you go! If you try that out and press H, you should jump really really high if you left the JumpPower value to 50.

NOTE: Don’t forget to check if the module is enabled in any method registered to an event as events do not take into account the activation state of the module.

5. Troubleshooting & Tips

5.1. The Player goes right through rigidbodies sometimes

You have 4 different ways to fix this problem, you can:

5.2. Changing what the Player collides with

To change what the player collides with, it’s as simple as going to the Physics window and changing the collision matrix: Edit 🡲 Project Settings 🡲 Physics
 

5.3 My footsteps doesn’t work

Make sure that you have done the following:

(See 3.2. Footstep Asset and 3.3. Footstep Data for more information)

6. Contact

If you have any questions, feedback, suggestions or problems with MFPP, you can contact me at spoonsoftware@protonmail.com