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
AudioSource
generated from this Audio systemExtensions.GizmosDrawCapsule(Vector3, float, float, float)
LayerMask.Contains(int)
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.
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
.
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:
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:
Slope Limit
- The character controller’s slope limit in degrees.Step Offset
- The character controller’s step offset in units.Skin Width
- The character’s collision skin width.Min Move Distance
- The minimum move distance of the character controller. (It is recommended to set this to 0)Radius
- The radius of the character’s capsule.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.
Camera
- The camera attached to this Player
.Height
- The height of this Player
.Camera Height
- The camera height of this Player
.Enable Camera Pitch Offset
- Determines if the forward pitch by pitch of the camera is enabled.Pitch Offset Curve
- The pitch offset curve, time dictates the pitch, value dictates the forward offset.Controls Enabled
- Are input controls enabled?Raw Input
- Should we use raw input for any axis?Mouse Locked
- Is the mouse locked?Mouse X Axis
- Axis name for the Mouse X axis.Mouse Y Axis
- Axis name for the Mouse Y axis.Mouse Sensitivity
- The sensitivity of the mouse.Mouse Sensitivity X Multiplier
- The X axis multiplier of the sensitivity of the mouse.Mouse Sensitivity Y Multiplier
- The Y axis multiplier of the sensitivity of the mouse.Mouse Smoothing
- Smoothness of the mouse movement.Horizontal Axis
- Axis name for the Horizontal axis.Vertical Axis
- Axis name for the Vertical axis.Jump Button
- Button name for the Jump button.Sprint Button
- Button name for the Sprint button.Crouch Button
- Button name for the Crouch button.Crouch Toggle Button
- Button name for the Crouch Toggle button (in toggle mode).Enable Overlap Recovery
- Enables or disables overlap recovery. Used to de-penetrate character controllers from static objects when an overlap is detected.Continuous Collision Detection
- If enabled, applies an extremely subtle noisy movement pass to the Player to allow for continuous collision detection in all cases.Continuous Collision Detection Strength
- The strength of the continuous detection movement pass. High value assures better collisions but more inaccurate movement. 0.01 is a good value in most cases.Continuous Collision Detection Passes
- The amount of continuous collision passes. High value assures better collisions but is more expensive to compute and character’s skin width feels “thicker”. 1 is the recommended value.Allow Mouse Move
- Should we allow mouse movement?Allow Movement
- Should we allow character movement?Speed
- The base walking speed.Acceleration
- The acceleration amount.Deceleration
- The deceleration amount.Slope Speed Multiplier
- The slope speed multiplier curve, ranges from [0 … 1] in the horizontal axis mapped to [0 … Slope Limit], vertical axis is the speed multiplier to apply.Air Control
- Should we allow air control?Air Accelerate
- The air acceleration amount.Smart Strafing
- Should we allow smart strafing? (Similar to Source Engine strafing)Vertical Strafing
- Should we allow vertical strafing? (Z local axis)Horizontal Strafing
- Should we allow vertical strafing? (X local axis)Strafing Speed
- The strafing speed for horizontal and vertical strafing. (Smart strafing not included)Allow Jump
- Should we allow jumping?Auto jump
- Should we allow auto-jumping?Power
- The power of the jump.Allow Sprint
- Should we allow sprinting?Speed Multiplier
- The speed multiplier of the base speed when sprinting.Allow Crouch
- Should we allow crouching?Allow Crouch Jump
- Should we allow crouch-jumping?Crouch Toggle
- Crouch toggling mode (by default Crouch Hold Only).Crouch Height
- The height of the player when crouching.Crouch Camera Height
- The camera height of the player when crouching.Crouching Speed
- The speed of the crouching action.Speed Multiplier
- The speed multiplier of the base speed when crouching.Footstep Asset
- The footstep asset to use.Is 3D
- Are the footsteps generated in 3D spatial blending?Global Volume
- The global volume of the footsteps.Range
- The audio range of the footsteps. Roll-off will be linear. Any value equal or less than zero disables the range and uses default logarithmic roll-off. If “Is 3D” is disabled, then this value is ignored.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
Default Footsteps Name
- The default footsteps name that we select from the Footsteps list. (See 3.3. Footstep Data for more information)Footsteps
- The list of footstep data. (See 3.3. Footstep Data for more information)Walk Timer
- The walking timer interval. 1 = 1 second between footsteps, 0.5 = 0.5 seconds between footsteps and so on. Lower is faster.Crouch Timer Multiplier
- Interval multiplier for the walking timer when crouching. Higher than 1 slows it down (e.g 1.4 = 1.4x interval length), lower and it speeds it up.Sprint Timer Multiplier
- Interval multiplier for the walking timer when sprinting. Higher than 1 slows it down, lower and it speeds it up (e.g 0.6 = 0.6x interval length).Crouch Volume
- Footstep volume when crouching.Walk Volume
- Footstep volume when walking.Sprint Volume
- Footstep volume when sprinting.Landing Minimum Velocity
- The minimum landing velocity.Landing Maximum Velocity
- The maximum landing velocity.Landing Volume Multiplier
- The final volume multiplier of the landing sounds.This is where you will add your footsteps, jumping and landing sounds, along with linking them to specific surfaces, materials & textures.
Name
- The name of the footstep data.Linked Materials
- Linked materials for this footstep data.Linked Textures
- Linked textures for this footstep data.Footstep Data
will retrieve the audio-clips assigned to the same Footstep Data
)Footstep Clips
- Footstep sounds.Jumping Clips
- Jumping sounds.Landing Clips
- Landing sounds.Min Pitch
- Minimum random pitch of a footstep.Max Pitch
- Maximum random pitch of a footstep.Min Pitch
and Max Pitch
to 1 if you do not want any random pitch)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.
FootstepAsset
assigned to our player, just make sure that you have a footstep data with an existing name in order for it to work.(See 2.0. Code Documentation for more information)
With Player modules you can extend the functionality of the Player
script however you would like.
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.
Bobs the camera as we walk and land.
Enabled
- Is this PlayerModule
enabled?Execution Order
- The execution order of this PlayerModule
, lower means earlier execution.Bob Amplitude
- The amplitude of the bobbing.Bob Speed
- The speed of the bobbing.Bob X
- The X axis animation curve of the bobbing.Bob Y
- The Y axis animation curve of the bobbing.Landing Bob Amplitude
- The amplitude of the landing bob.Landing Bob Speed
- The speed recover of the landing bob.Landing Bob Lerp Speed
- The speed recover lerp (smoothing) of the landing bob.Pick up rigidbodies and carry them around.
Enabled
- Is this PlayerModule
enabled?Execution Order
- The execution order of this PlayerModule
, lower means earlier execution.Max Pickup Distance
- The maximum pickup distance.Max Pickup Mass
- The maximum pickup mass.Move Force
- The force of the picked up object movement.Pick Up Button
- Pick up button.Pushes rigidbodies around as you attempt to walk through them.
Enabled
- Is this PlayerModule
enabled?Execution Order
- The execution order of this PlayerModule
, lower means earlier execution.Push Force
- The pushing force.Allows you to climb on ladders.
Enabled
- Is this PlayerModule
enabled?Execution Order
- The execution order of this PlayerModule
, lower means earlier execution.Ladder Layer Mask
- The layer mask of the ladder(s).Climb Speed
- The climb speed of the player on ladders.Climb Step Timer
- The step interval of the player on ladders.Grab Force Multiplier
- The grab force multiplier when grabbing a ladder.Grab Duration
- The grab duration in seconds (until we grab a ladder).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.)
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.
You have 4 different ways to fix this problem, you can:
CharacterController
component in your player.Fixed Timestep
property in the Time window: Edit 🡲 Project Settings 🡲 Time
.Continuous Collision Detection Strength
property in the Player
script.Continuous Collision Detection Passes
property in the Player
script.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
Make sure that you have done the following:
MeshRenderer
or Terrain
is attached to the collider you’re walking on.(See 3.2. Footstep Asset and 3.3. Footstep Data for more information)
If you have any questions, feedback, suggestions or problems with MFPP, you can contact me at spoonsoftware@protonmail.com