Table of Contents
An Open Source 3d character and character controller for the Godot game engine.
This is a third person character controller designed to work both with the keyboard and a gamepad. It features a camera that can auto-rotate or that can be controlled with a joystick.
The 3D Third Person Character Controller is made of two scenes:
Camera.tscn
- A 3D camera rig with a state machine for aimingPlayer.tscn
- AKinematicBody
with a state machine for player movement. Contains an instance ofCamera
. It also includes the animated 3D mannequin.
To use the default character, instance Player
in your game. See Game.tscn
for an example. In this demo, the obstacles are mesh instances with static body collisions making up a cube world.
The game supports both mouse and keyboard, and the gamepad.
The scene that deals with the movement, collision, and logic of the player. The player is a KinematicBody with a capsule collision shape, and the movement logic is within a Finite State Machine.
The scene also holds an instance of the PlayerMesh
for animation purposes. This scene lives in the PlayerMesh.tscn
scene. It holds the skeletal rig for the mesh's animation, the 3D model of the body and head sepearately, and the animation tree and player to control the animation workflow of the model. The lot is wrapped up in a spatial node with some logic to transition to which animation based on which state the player is in.
The scene that deals with the Camera movement. It follows the Player in the game, but in code it moves and rotates separately from it. It has a SpringArm
node to help with preventing collision with level geometry - moving the viewpoint forwards to prevent moving the camera inside geometry. It also has a system that holds the raycast for aiming-mode, and the 3D sprite that is a projected reticule. The logic is held in a finite state machine.
To change the player and the camera's behavior, you need to change properties on the corresponding states in their state machine.
Most of the configuration available for player movement are located on the Move
state in the Player scene - the player speed and the rotational speed.
The Camera has more options. On the main Camera state in the Camera scene are items like the default field of view, whether Y is inverted, and sensitivity.
In addition, the Aim state allows some finer-tuned changes, like whether the aiming camera is first or third person, and by how much it should be offset over-the-shoulder of the character.
While the scenes can be modified extensively with new nodes and raw code, the state machine model allow for some simple, new functionality with relative ease.
As an example, there is the Extensions
folder which contains additional player states for using the aiming view to fire a hookshot that pulls you towards the reticle. Once those states have been added to the Player's Move
state, you only need to replace the return statement in Move's enter
with code like owner.camera.connect("aim_fired", self, "on_Camera_aim_fired")
and Move's exit
with code like owner.camera.disconnect("aim_fired", self, "on_Camera_aim_fired")
- The Godot mannequin is a character made by Luciano Muñoz In blender 2.80.
- Godot code by Josh aka Cheeseness
- Additional code by Francois Belair aka Razoric480
This free series is sponsored by our platformer game creation course.
GDQuest is a social company focused on education and bringing people together around Free Software.
We share the techniques professionals use to make games and open source the code for most of our projects on our GitHub page.
You can: