No edit summary Tag: Visual edit |
m (Added caveat) Tag: Visual edit |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | This script allows for integration with [https://opsive.com/solutions/character-solution/ Opsive's Ultimate Character Controller] ([https://opsive.com/assets/ufps/ UFPS 2] included). |
+ | This script allows for integration with [https://opsive.com/solutions/character-solution/ Opsive's Ultimate Character Controller] ([https://opsive.com/assets/ufps/ 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: |
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 |
# 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 |
# Otherwise, you can remove AC's MainCamera, drop the UCC MainCamera into the scene, and attach AC's '''MainCamera''' component |
||
Line 22: | Line 22: | ||
private Vector2 defaultMouseSensitivity;<br> |
private Vector2 defaultMouseSensitivity;<br> |
||
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br> |
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br> |
||
− | private |
+ | private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br> |
private Player player;<br> |
private Player player;<br> |
||
<br> |
<br> |
||
Line 33: | Line 33: | ||
{<br> |
{<br> |
||
player = GetComponent <AC.Player>();<br> |
player = GetComponent <AC.Player>();<br> |
||
− | + | playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();<br> |
|
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br> |
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br> |
||
<br> |
<br> |
||
− | if ( |
+ | if (playerInput != null)<br> |
{<br> |
{<br> |
||
− | defaultMouseSensitivity = |
+ | defaultMouseSensitivity = playerInput.LookSensitivity;<br> |
}<br> |
}<br> |
||
}<br> |
}<br> |
||
Line 57: | Line 57: | ||
private void Update ()<br> |
private void Update ()<br> |
||
{<br> |
{<br> |
||
− | if ( |
+ | if (playerInput != null)<br> |
{<br> |
{<br> |
||
− | + | playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())<br> |
|
? defaultMouseSensitivity<br> |
? defaultMouseSensitivity<br> |
||
: Vector2.zero;<br> |
: Vector2.zero;<br> |
||
Line 87: | Line 87: | ||
private void OnTeleport ()<br> |
private void OnTeleport ()<br> |
||
{<br> |
{<br> |
||
− | ultimateCharacterLocomotion. |
+ | ultimateCharacterLocomotion.SetPositionAndRotation (KickStarter.player.GetTargetPosition (), KickStarter.player.GetTargetRotation (), true);<br> |
− | ultimateCharacterLocomotion.SetRotation (KickStarter.player.GetTargetRotation (), true);<br> |
||
}<br> |
}<br> |
||
<br> |
<br> |
||
Line 94: | Line 93: | ||
<br> |
<br> |
||
} |
} |
||
+ | |||
+ | |||
Revision as of 13:33, 12 January 2019
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
}