Adventure Creator Wikia
m (Further instruction fixes)
Tag: Visual edit
No edit summary
Tag: Visual edit
Line 7: Line 7:
 
# Attach the script below as a new component on the RigidbodyFPSController root object
 
# Attach the script below as a new component on the RigidbodyFPSController root object
 
# Tag this object as Player
 
# Tag this object as Player
# In the AC Player component, set the '''Animation engine''' to '''Custom'''
+
# In the AC Player component, set the '''Animation engine''' to '''Custom''' and the''' Motion control '''to''' Manual'''
 
# Make the RigidbodyFPSController a prefab, and remove it from the scene
 
# Make the RigidbodyFPSController a prefab, and remove it from the scene
 
# Unset the Scene Manager's Default Camera and Default PlayerStart fields
 
# Unset the Scene Manager's Default Camera and Default PlayerStart fields

Revision as of 12:27, 12 March 2020

This script allows for integration with Unity's First Person Controller, as included in their Standard Assets package.

To use it:

  1. Set your game's Movement method to First Person
  2. Find the RigidbodyFPSController, and untag its Camera child so that it is no longer tagged as MainCamera
  3. Attach a Constant ID component to the Camera child, and check Retain in prefab?.
  4. Attach the script below as a new component on the RigidbodyFPSController root object
  5. Tag this object as Player
  6. In the AC Player component, set the Animation engine to Custom and the Motion control to Manual
  7. Make the RigidbodyFPSController a prefab, and remove it from the scene
  8. Unset the Scene Manager's Default Camera and Default PlayerStart fields
  9. Create a new OnStart Cutscene with a Camera: Switch Action, and assign the prefab's Camera child in the New camera field
  10. In the same Cutscene, create an Object: Teleport Action to set the player's correct starting position/rotation.

UnityFirstPersonIntegration.cs:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;
using UnityStandardAssets.Characters.FirstPerson;

[RequireComponent (typeof (RigidbodyFirstPersonController))]
[RequireComponent (typeof (AC.Player))]
public class UnityFirstPersonIntegration : MonoBehaviour
{

#region Variables

private RigidbodyFirstPersonController firstPerson;
private Player player;

#endregion


#region UnityStandards

private void Awake ()
{
player = GetComponent <Player>();
firstPerson = GetComponent <RigidbodyFirstPersonController>();
}


private void OnEnable ()
{
EventManager.OnEnterGameState += OnEnterGameState;
EventManager.OnFinishLoading += OnFinishLoading;
}


private void OnDisable ()
{
EventManager.OnEnterGameState -= OnEnterGameState;
EventManager.OnFinishLoading -= OnFinishLoading;
}


private void Update ()
{
firstPerson.mouseLook.SetCursorLock (KickStarter.playerInput.IsCursorLocked ());
}

#endregion


#region CustomEvents

private void OnEnterGameState (GameState newGameState)
{
if (newGameState == GameState.Normal)
{
firstPerson.enabled = true;
player.motionControl = MotionControl.Manual;
}
else
{
firstPerson.enabled = false;
player.motionControl = MotionControl.Automatic;
}

ResetMouseLook ();
}



private void OnTeleport ()
{
ResetMouseLook ();
}

#endregion


#region PrivateFunctions

private void OnFinishLoading ()
{
ResetMouseLook ();
}


private void ResetMouseLook ()
{
firstPerson.mouseLook.Init (transform, firstPerson.cam.transform);
}

#endregion

}