How Can We Help?

3rd Person to 1st Person

The Camera Controller uses different motors to achieve different behaviors. So, we can use one of the 3rd Person motors to have our camera work for third-person games and we can use the 1st Person motor to work for first-person games.

With the transition motors, we can have our game transition between the 3rd Person motors and the 1st Person motors. This tutorial will show you a very basic way of doing that.

Remembering that the Camera Controller is not a “character controller”, I’ll use the Third Person Motion Controller as the character controller and change its behavior to match the camera style.

Note that this tutorial doesn’t address the “artistic” issues that arise when transitioning between third-person and first-person views. For more information about the hurdles you’ll have to solve, see this post: Can I use the Motion Controller with first-person games?

1. Setup the scene

For this, just follow the standard Camera Controller and Motion Controller quick-start setup.

We’re looking to create a scene where the character is using a third-person movement style.

Below is how my components are setup:

For the Motion Controller above, we are just using some basic motions:

  1. Basic Idle for idling
  2. Basic Walk Run Pivot for third-person play
  3. Basic Walk Run Strafe for first-person play (disabled)
  4. Jump for jumping
  5. Fall for falling

As we transition from third-person to first-person, we’ll toggle these motions and and off to fit the camera. I’ll explain that later.

2. Setup the Camera Motors

In the picture above, you’ll see the Camera Controller is setup with 4 motors:

  1. 3rd Person Follow for third-person mode
  2. 1st Person View for first-person mode
  3. Transition for going from 3rd person to 1st person
  4. Transition for going from 1st person to 3rd person

Below is how I set each of them up:

With the Transition motors, there’s a couple of things to notice:

  1. The “Start Index” is the motor you would be coming from.
  2. The “End Index” is the motor you would be transitioning to.
  3. The “Action Alias” is the button that triggers the transition (Interact = ‘F’).
  4. “Test Only In Start” means we’ll only trigger the transition if the action alias occurs in the starting motor.

3. Switching Modes

Out-of-the-box the Motion Controller doesn’t know if you transitioned from a third-person mode to a first-person mode. So, it has to be done with code.

When the transition starts, we’ll determine which mode we’re heading to and configure the Motion Controller. 

This is true for any character controller you use. In this example, I’m just using my Motion Controller.

So, the code below is what I’m using to react to the “Camera Motor Activated” event and change the settings on the Motion Controller:

using UnityEngine;
using com.ootii.Actors.AnimationControllers;
using com.ootii.Cameras;
using com.ootii.Messages;

public class demo_MotionController_code : MonoBehaviour
{
    private MotionController lMC;
    private BasicWalkRunPivot lPivot;
    private BasicWalkRunStrafe lStrafe;

    private void Start()
    {
        MotionController lMC = Component.FindObjectOfType();
        if (lMC == null) { return; }

        lPivot = lMC.GetMotion();
        lStrafe = lMC.GetMotion();
    }

    public void OnCameraTransition(IMessage rMessage)
    {
        if (rMessage.ID != EnumMessageID.MSG_CAMERA_MOTOR_ACTIVATE) { return; }
        if (lPivot == null || lStrafe == null) { return; }

        CameraMessage lMessage = rMessage as CameraMessage;
        if (lMessage == null) { return; }

        if (lMessage.Motor.Name == "To 1st Person")
        {
            lPivot.IsEnabled = false;
            lStrafe.IsEnabled = true;
        }
        else if (lMessage.Motor.Name == "To 3rd Person")
        {
            lPivot.IsEnabled = true;
            lStrafe.IsEnabled = false;
        }
    }
} 

In the code above, the OnCameraTransition(…) function will be called when the Camera Controller activates a new camera motor. 

We’ll add this new code to our Camera Controller’s GameObject. Then, we’ll tell the Camera Controller to use it. See below:

Summary

So, what we did was setup the Camera Controller and our character controller to support both third-person and first-person mode. Then, we use the code to configure the character controller when the Camera Controller transitioned from one mode to another.

You’ll have to think about the “artistic” issue and configure them as needed. However, the basic steps above should be a good starting point.

I went ahead and zipped up the scene and code. If you install the Camera Controller and the Motion Controller, you’ll just unzip these files in the Camera Controller’s demo folder:

<project>\Assets\ootii\_Demos\CameraController\Scenes

Download the files from here.

Page Contents