A First-Person Controller for Unity.
🧪 EXPERIMENTAL This project is experimental. It is still under development, so it may be unstable. It is not optimized and is largely untested. Do not use this project in critical projects.
This package includes a First-Person Controller for Unity. Check out the Features section for a detailed list of all features of the controller. The footage below shows the open-source sample project "Mapper's Peak" using the First-Person Controller.
- Install the First Person Controller: Install this package as described below.
- Install UniRx: The package depends on UniRx. Unfortunately, this dependency cannot be included automatically; the reason is described below in the "Special Dependencies" section. You have to include UniRx in your project. UniRx is available as UPM package or you can import it from the Asset Store.
- Update to Unity's new Input System This package uses Unity's Input System package. When asked from Unity, update to Unity's new Input System. Alternatively, you can implement your own
FirstPersonControllerInput
class and ignore the existing PlayerInput folder. - Explore your scene: Add the "FirstPersonPlayer" prefab from the package to your scene. Now you can explore your scene with the First-Person Controller.
I recommend installing this package from a Git URL using the Package Manager window. This involves the following steps:
- Open the Package Manager window in your Unity editor (Window ➜ Package Manager)
- Click "+" in the upper left corner ➜ "Add package from git URL"
- Enter the Git URL of the latest release:
https://github.com/dyrdadev/first-person-controller-for-unity.git#0.0.4
and click "Add"
You can find more information here.
The controller depends on UniRx. UniRx is the implementation of ReactiveX for Unity. Unfortunately, it is not possible to add it as a dependency because Unity doesn’t support Git URLs for indirect dependencies. UniRx has to be installed manually in your project that uses the First Person Controller. UniRx is available as UPM package or you can import it from the Asset Store.
If you want to learn UniRx to extend the controller or use it for other components, I recommend the tutorial series "ReactiveX and Unity3D" by Tyler Coles. Also check out the official material of UniRx and ReactiveX.
The project includes player input and uses Unity's new Input System Package. The new system replaces the classic input system with the Input Manager in UnityEngine.Input
. On import, Unity asks you if your project should be updated to the new Input System. If you need the UnityEngine.Input
input system, you can set the "Active Input Handling" option in the Player settings (Project Settings ➜ Player ➜ Other Settings) to Both
. Then you can use the new Input System Package System and the old Input Manager with the UnityEngine.Input
class.
If you do not want to switch to the new input system, you can implement your own FirstPersonControllerInput
class that uses the input system of your choice.
The First-Person Controller supports a mouse + keyboard input scheme and a gamepad input scheme. You can edit the input schemes and add new ones in the "FirstPersonInputAction" Input Action Asset. Check out the manual of the Input System for further information.
The First-Person Controller implements physics-based locomotion allowing you to move around, run, and jump.
The controller implements an ICharacterSignals
interface for character effects such as character audio or camera effects. The interface offers you an easy way to implement your own effects. The package currently includes the following effects, which are already implemented:
- Head Bob The package includes an optional head-bob effect for walking and running. The effect moves the camera slightly up and down to simulate the movement.
- Sound Effects The package includes an optional component for sound effects of the character.
This package is licensed under an MIT license. See the LICENSE file for details.
This project was inspired by the tutorial series "ReactiveX and Unity3D" by Tyler Coles. Many approaches of this tutorial series inspired features of this project. And the tutorial is what introduced me to Reactive Programming in Unity in the first place. I recommend checking out the tutorial series.
This project was created by Daniel Dyrda.
Daniel: If you want to support me and my projects, you can follow me on GitHub (dyrdadev) and Mastodon. Just come by and say hello, I would love to hear how you are using the project.
If you want to contribute to this project, you are welcome to do so. Just write to me and we will find a way to collaborate.