Forum rules - please read before posting.

AC integration with Unity Starter Assets - Third Person Character Controller

Hi Chris,

I am currently trying to implement a player with Third Person Character Controller from the Unity Start Assets which also requires Unity new Input System.

My game target is : The Last Of Us alike (Third Person Game)
Asset to integrate : Starter Asset
What I have done recently is;

  • Adding AC Player script component to player gameObject
  • Adding AC Paths script component to player gameObject
  • Following this tutorial and got stucked when scripting the CustomControllerLink.
  • Following Input System Integration tutorial and and still has no idea what to continue .
  • The AC Interface settings -> Movement method set to direct (do I need to assign this too since I use Custom Controller Script ? ).

The problem is

  • The asset use Cinemachine as third person camera and located separately from Player gameObject, would that be possible to work with AC camera (switch) since Cinemachine has no camera component in it ?
  • Does this set up enough to work with AC as Player ?

My question

  • Do I need to integrate this asset as similar as AC with ooti's integration? if yes, what adjusments do I need to integrate ?
  • What should I do with the Cinemachine in order to work with AC Camera switching ?
  • I need your advice Chris.

Pictures

Thanks Chris.

Comments

  • Welcome to the community, @Paul.

    Do I need to integrate this asset as similar as AC with ooti's integration? if yes, what adjusments do I need to integrate ?

    Any script that bridges two assets together will need to account for the way in which you want to integrate them. The exact functions involved will depend on the asset you're using, but the main takeaway from the tutorial is that - in a typical case - AC should be able to control the character during cutscenes - and the other motion controller during gameplay (unless point-and-click motion is involved).

    To have another asset take control over the Player at all times, you can just set the Player component's "Motion control" field to "Manual", so that it relies on another asset to control its motion.

    What script have you gotten so far, and what are your needs so far as which asset controls the characer at any given time?

    What should I do with the Cinemachine in order to work with AC Camera switching ?

    A script to change a Cinemachine camera's priority can be found on the wiki here. A thread on the forum here with an alternative user script to automate things can be found here.

  • edited December 2021

    Update: I've been looking into the controller on my end. It does seem fairly basic, and not too well suited to being integrated with other assets without modifying the motion controller's code itself.

    IMO, the best way to work with the controller as-is is to just disable it whenever you're in an AC cutscene, and give AC control over it during that time:

    using UnityEngine;
    using AC;
    using StarterAssets;
    
    public class ThirdPersonControllerIntegration : MonoBehaviour
    {
    
        private AC.Char acCharacter;
        private ThirdPersonController thirdPersonController;
    
        private void Start ()
        {
            acCharacter = GetComponent<AC.Char> ();
            thirdPersonController = GetComponent<ThirdPersonController> ();
        }
    
        private void LateUpdate ()
        {
            if (!KickStarter.stateHandler.IsInGameplay () ||
                (!acCharacter.IsPlayer || KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick)
                || acCharacter.IsMovingAlongPath ())
            {
                acCharacter.motionControl = MotionControl.Automatic;
                thirdPersonController.enabled = false;
            }
            else
            {
                acCharacter.motionControl = MotionControl.Manual;
                thirdPersonController.enabled = true;
            }
        }
    
    }
    

    Attach this to the controller along with AC's Player component, and set the "Animation engine" to "Mecanim".

    Though, since the controller also deals with the camera motion, this will also prevent the camera from being controllable. To get around this, you would have to move the ThirdPersonController script's camera-related code into a separate script so that it is unaffected.

    As the controller relies on Unity's Input System package, you will need to have the Input System Integration script present, but it shouldn't need modifying to have the above work.

  • edited December 2021

    Hi Chris thanks for the answer, sorry for the late reply.

    Yes, I already did what you suggest. Basically as far as I know after understanding the script you wrote above, It will deactivate ThirdPersonController script while certain conditions are met right (i.e. Pausing, cutscenes) ?

    And I tried to change the Animation Engine from custom to mecanim, but I found problems where walk/running animation not triggered (not walk nor running) and the player looks jaggy when moving.

    Here are some clips;

    Thanks Chris.

  • Basically as far as I know after understanding the script you wrote above, It will deactivate ThirdPersonController script while certain conditions are met right (i.e. Pausing, cutscenes) ?

    That's correct.

    As ThirdPersonController script reads inputs directly and converts them into motion, overriding motion is a case of either disabling it, or modifying the inputs.

    I tried the latter approach, but the process of converting an input direction into a movement direction is handled from within ThirdPersonController, which causes issues if the camera moves during an AC cutscene.

    With the approach of disabling ThirdPersonController completely, it'll be necessary to leverage AC's Mecanim animation engine to have the character animate properly during cutscenes. I myself don't encounter the issue you face in the video, but it may be a case of execution orders - since both AC and ThirdPersonController are competing for control over the Animator's "Speed" parameter.

    One way to get around this would be to update the relative Script Execution Order values between AC's StateHandler component (which handles AC's updating) and the ThirdPersonController. If ThirdPersonController's is higher, it'll update 2nd and in theory apply it's own change over the Speed parameter after AC.

    The other way would be to have the integration script clear the "Speed" parameter from the Player's Inspector when not in a cutscene, so that it doesn't control it when it shouldn't. Something like this:

    using UnityEngine;
    using AC;
    using StarterAssets;
    
    public class ThirdPersonControllerIntegration : MonoBehaviour
    {
    
        private AC.Char acCharacter;
        private ThirdPersonController thirdPersonController;
    
        private void Start ()
        {
            acCharacter = GetComponent<AC.Char> ();
            thirdPersonController = GetComponent<ThirdPersonController> ();
        }
    
        private void LateUpdate ()
        {
            if (!KickStarter.stateHandler.IsInGameplay () ||
                (!acCharacter.IsPlayer || KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick)
                || acCharacter.IsMovingAlongPath ())
            {
                acCharacter.motionControl = MotionControl.Automatic;
                thirdPersonController.enabled = false;
                acCharacter.moveSpeedParameter = "Speed";
            }
            else
            {
                acCharacter.motionControl = MotionControl.Manual;
                thirdPersonController.enabled = true;
                acCharacter.moveSpeedParameter = string.Empty;
            }
        }
    
    }
    
  • Hi Chris, thanks for the help so far.

    Eeverything works well as you said above, what I have done :

    • Change player to mechanim and added extra code in ThirdPersonControllerIntegration.
    • Separate ThirdPersonController camera related code to a new Camera Rotation script and works just fine.
    • On Unity Input integration script, escape is assigned.

    My problems and questions are :

    • Since I use Cinemachine, do I need to change Cinemachine camera's priority in order to do Camera switch, fade, etc. ?
    • When action list is playing (for example, when I click any hotspot
      ) does it automatically pause the game, or do I need to set inside the action list to pause the game ?

    Thanks Chris.

  • edited December 2021

    Since I use Cinemachine, do I need to change Cinemachine camera's priority in order to do Camera switch, fade, etc. ?

    To switch between different Cinemachine cameras, yes: it's a case of changing each's priority. AC will treat the Cinemachine Brain as a single GameCamera, so it's not possible to use AC's Camera: Switch Action to switch between individual Cinemachine VirtualCameras.

    A thread on this topic, with script solutions, can be found here. A page dealing with this can also be found on the AC wiki here.

    When action list is playing (for example, when I click any hotspot) does it automatically pause the game, or do I need to set inside the action list to pause the game ?

    Only menus that have "Paused when enabled?" checked can pause the game - or are you referring to blocking gameplay, rather than freezing time?

    An ActionList will, by default, block gameplay - yes. You can configure this at the top of its Inspector with its "When running" field. Setting this to "Run In Background" will allow gameplay to continue while it runs.

  • Hi Chris, thanks for responding.

    Ah sorry I think I did not explain it clearly, I intended to switch between Third Person Cinemachine to AC Game Camera/Simple Camera when cutscene begins for example.

  • Thanks for the clarification.

    So long as its the Cinemachine Brain you make visible to AC (by attaching AC's Basic Camera component to it), then it can be treated like a regular GameCamera regardless of what Cinemachinr VirtualCamera it's actually representing. You would be able to use other AC cameras using Actions in cutscenes as normal.

    For more on using the "Basic Camera" component to set things up in this way, see the Manual's "Working with Cinemachine" chapter.

    This method also allows you to use AC's MainCamera tracks in Timeline, allowing you to switch camera within Timeline sequences as well as within ActionLists - more on this can be found in the Manual's "Working with Timeline" section.

  • Hi Chris, thanks for replying.

    Happy to hear the integration is not as hard as I imagined. I already done the steps both you mentioned above and also from the manual. But mine isn't working yet.
    What I already did was :

    • Adding Basic camera script component to Cinemachine Brain Main camera
    • Testing out with small implementation from cinemachine cam to Simple camera back to cinemachine cam again with simple hotspot and action list.

    Here are is link for a test video and pictures :
    GDrive

    Thanks Chris

  • Are you getting any camera-related messages in the Console around this time?

    I can't be exactly sure from the screenshots, but it looks like you only have one "MainCamera" in the scene.

    AC's MainCamera and CM's "Cinemachine Brain" camera need to be separate objects. If AC's MainCamera is missing, you can auto-add it by clicking "Without folders" at the top of the Scene Manager - but check that your current MainCamera doesn't have both the Cinemachine Brain and MainCamera components.

    For the AC<-> CM camera-switch you're looking for, you'll need these to be separate objects:

    - AC MainCamera (Camera and MainCamera components)
    - CM MainCamera (Cinemachine Brain and Basic Camera components)
    - AC SimpleCamera (Camera and Basic Camera components)
    - CM VirtualCamera
    
  • Hi Chris, Yes it works.

    Thanks a lot but I have a problem, the camera switching works well, but now the player movement looks very jaggy. Do you know why ?

    Video

    Thanks Chris

  • edited December 2021

    When running past static objects up-close, are they moving across the screen jaggy as well - or is it only ever the player?

    Does your Player have a Rigidbody that uses Interpolation?

    As AC's MainCamera is now following the Cinemachine Brain, it's necessary for AC to update after Cinemachine. See the Manual's chapter on Cinemachine, but you can do this by setting AC’s StateHandler script’s Execution Order to a value larger than the CinemachineBrain script.

    Cinemachine also should have an option related to updating in update vs fixed update - playing with that may also improve results.

  • edited December 2021

    Hi Chris, I am so happy to find out your suggestion is working!

    But first, yes it is only the player has jittery moves.

    I use Character Controller instead of Rigidbody for the movement.

    I set the AC's StateHandler srcript execution order to a value larger than the Cinemachine related scripts and it works.

    Much thanks to you Chris, I really appreciate the support you gave to us and for all the quick responses. Jesus bless you brother.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.