Adventure Creator Wikia
No edit summary
Tag: Visual edit
No edit summary
Tag: Visual edit
(5 intermediate revisions 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:
# Set your game's '''Movement method''' to '''First Person'''
+
# 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 12: Line 12:
 
using Opsive.UltimateCharacterController.Input;<br>
 
using Opsive.UltimateCharacterController.Input;<br>
 
using Opsive.UltimateCharacterController.Character;<br>
 
using Opsive.UltimateCharacterController.Character;<br>
using Opsive.UltimateCharacterController.Events;<br>
+
using Opsive.Shared.Events;<br>
  +
<br>
 
<br>
 
<br>
 
[RequireComponent (typeof (UltimateCharacterLocomotion))]<br>
 
[RequireComponent (typeof (UltimateCharacterLocomotion))]<br>
 
public class AdventureCreatorControllerHandler : MonoBehaviour<br>
 
public class AdventureCreatorControllerHandler : MonoBehaviour<br>
 
{<br>
 
{<br>
  +
<br>
 
<br>
 
<br>
 
#region Variables<br>
 
#region Variables<br>
Line 22: Line 24:
 
private Vector2 defaultMouseSensitivity;<br>
 
private Vector2 defaultMouseSensitivity;<br>
 
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br>
 
private UltimateCharacterLocomotion ultimateCharacterLocomotion;<br>
private UnityInput unityInput;<br>
+
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;<br>
private Player player;<br>
+
private AC.Player player;<br>
 
<br>
 
<br>
 
#endregion<br>
 
#endregion<br>
Line 33: Line 35:
 
{<br>
 
{<br>
 
player = GetComponent <AC.Player>();<br>
 
player = GetComponent <AC.Player>();<br>
unityInput = GetComponent <UnityInput>();<br>
+
playerInput = GetComponent <Opsive.UltimateCharacterController.Input.PlayerInput>();<br>
 
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br>
 
ultimateCharacterLocomotion = GetComponent <UltimateCharacterLocomotion>();<br>
 
<br>
 
<br>
if (unityInput != null)<br>
+
if (playerInput != null)<br>
 
{<br>
 
{<br>
defaultMouseSensitivity = unityInput.LookSensitivity;<br>
+
defaultMouseSensitivity = playerInput.LookSensitivity;<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
Line 52: Line 54:
 
{<br>
 
{<br>
 
EventManager.OnEnterGameState -= OnEnterGameState;<br>
 
EventManager.OnEnterGameState -= OnEnterGameState;<br>
  +
}<br>
  +
<br>
  +
<br>
  +
private void Start ()<br>
  +
{<br>
  +
OnEnterGameState (GameState.Normal);<br>
 
}<br>
 
}<br>
 
<br>
 
<br>
Line 57: Line 65:
 
private void Update ()<br>
 
private void Update ()<br>
 
{<br>
 
{<br>
if (unityInput != null)<br>
+
if (playerInput != null)<br>
 
{<br>
 
{<br>
unityInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())<br>
+
playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())<br>
 
? defaultMouseSensitivity<br>
 
? defaultMouseSensitivity<br>
 
: Vector2.zero;<br>
 
: Vector2.zero;<br>
  +
<br>
  +
if (KickStarter.stateHandler.IsInGameplay ())<br>
  +
{<br>
  +
if (KickStarter.playerInput.CanDirectControlPlayer ())<br>
  +
{<br>
  +
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);<br>
  +
player.motionControl = MotionControl.Manual;<br>
  +
}<br>
  +
else<br>
  +
{<br>
  +
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);<br>
  +
player.motionControl = MotionControl.Automatic;<br>
  +
}<br>
  +
}<br>
 
}<br>
 
}<br>
 
}<br>
 
}<br>
Line 87: Line 109:
 
private void OnTeleport ()<br>
 
private void OnTeleport ()<br>
 
{<br>
 
{<br>
ultimateCharacterLocomotion.SetPosition (KickStarter.player.GetTargetPosition (), true);<br>
+
ultimateCharacterLocomotion.SetPositionAndRotation (KickStarter.player.GetTargetPosition (), KickStarter.player.GetTargetRotation (), true);<br>
ultimateCharacterLocomotion.SetRotation (KickStarter.player.GetTargetRotation (), true);<br>
 
 
}<br>
 
}<br>
 
<br>
 
<br>
Line 94: Line 115:
 
<br>
 
<br>
 
}
 
}
  +
   
 
 

Revision as of 08:40, 19 April 2020

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:

  1. If using UFPS, set your game's Movement method to First Person
  2. Use the Scene Manager to Organise scene objects, and opt to Convert the UCC's MainCamera into an AC one
  3. Otherwise, you can remove AC's MainCamera, drop the UCC MainCamera into the scene, and attach AC's MainCamera component
  4. Find the UCC Player GameObject in the scene, and attach both AC's Player component, and the script below (AdventureCreatorControllerHandler.cs)
  5. 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.Shared.Events;


[RequireComponent (typeof (UltimateCharacterLocomotion))]
public class AdventureCreatorControllerHandler : MonoBehaviour
{


#region Variables

private Vector2 defaultMouseSensitivity;
private UltimateCharacterLocomotion ultimateCharacterLocomotion;
private Opsive.UltimateCharacterController.Input.PlayerInput playerInput;
private AC.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 Start ()
{
OnEnterGameState (GameState.Normal);
}


private void Update ()
{
if (playerInput != null)
{
playerInput.LookSensitivity = (KickStarter.playerInput.IsCursorLocked ())
? defaultMouseSensitivity
: Vector2.zero;

if (KickStarter.stateHandler.IsInGameplay ())
{
if (KickStarter.playerInput.CanDirectControlPlayer ())
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", true);
player.motionControl = MotionControl.Manual;
}
else
{
EventHandler.ExecuteEvent <bool> (gameObject, "OnEnableGameplayInput", false);
player.motionControl = MotionControl.Automatic;
}
}
}
}

#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

}