This script allows for integration with Opsive's Ultimate Character Controller (UFPS 2 included). Note: This currently only allows for control through UCC - not a hybrid with AC, e.g. point and click movement.
To use it:
- If using UFPS, set your game's Movement method to First Person
- Use the Scene Manager to Organise scene objects, and opt to Convert the UCC's MainCamera into an AC one
- Otherwise, you can remove AC's MainCamera, drop the UCC MainCamera into the scene, and attach AC's MainCamera component
- Find the UCC Player GameObject in the scene, and attach both AC's Player component, and the script below (AdventureCreatorControllerHandler.cs)
- In the AC Player component, set the Animation engine to Custom
AdventureCreatorControllerHandler.cs:
using UnityEngine;
using AC;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Events;
[RequireComponent (typeof (UltimateCharacterLocomotion))]
public class AdventureCreatorControllerHandler : MonoBehaviour
{
#region Variables
private Vector2 defaultMouseSensitivity;
private UltimateCharacterLocomotion ultimateCharacterLocomotion;
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;
private Player player;
#endregion
#region UnityStandards
private void Awake ()
{
player = GetComponent <AC.Player>();
playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();
if (playerInput != null)
{
defaultMouseSensitivity = playerInput.LookSensitivity;
}
}
private void OnEnable ()
{
EventManager.OnEnterGameState += OnEnterGameState;
}
private void OnDisable ()
{
EventManager.OnEnterGameState -= OnEnterGameState;
}
private void Update ()
{
if (playerInput != null)
{
playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())
? defaultMouseSensitivity
: Vector2.zero;
}
}
#endregion
#region CustomEvents
private void OnEnterGameState (GameState newGameState)
{
if (newGameState == GameState.Normal)
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);
player.motionControl = MotionControl.Manual;
}
else
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);
player.motionControl = MotionControl.Automatic;
}
}
private void OnTeleport ()
{
ultimateCharacterLocomotion.SetPositionAndRotation (KickStarter.player.GetTargetPosition (), KickStarter.player.GetTargetRotation (), true);
}
#endregion
}