Adventure Creator Wikia
Advertisement

This script allows for integration with Unity's Starter Assets - First Person Controller asset.

To use it:

  1. Import AC into a project that is already set up with the Third Person Controller asset
  2. Copy/paste the script below into a C# file named StarterAssetsInput_AC
  3. Locate the asset's PlayerArmature prefab, and remove its Starter Assets Input component
  4. Add the new Starter Assets Input AC component, and check AC Turns Camera
  5. Add AC's Player component, and set the Animation engine to Mecanim, and clear the parameter fields beneath

StarterAssetsInput_AC.cs:

using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
using AC;

namespace StarterAssets
{
	
	public class StarterAssetsInputs_AC : StarterAssetsInputs
	{
	
		public bool acTurnsCamera;
	
		AC.Char acCharacter;
		bool underACControl;
		
		void Awake ()
		{
			acCharacter = GetComponent<AC.Char> ();
			acCharacter.motionControl = MotionControl.Manual;
		}
		
		void Update ()
		{
			underACControl = !KickStarter.stateHandler.IsInGameplay () ||
							 (!acCharacter.IsPlayer || KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick) ||
							 acCharacter.IsMovingAlongPath ();
				
			if (underACControl)
			{
				Vector3 moveDirection = acCharacter.GetTargetPosition () - transform.position;
				MoveInput (moveDirection);
			
				if (acTurnsCamera)
				{
					Vector3 lookDirection = acCharacter.GetTargetRotation () * Vector3.forward;
					lookDirection.y = 0f;
					LookInput (lookDirection);
				}
			}
		}
		
		private Vector2 GetInputVector (Vector3 worldDirection)
		{
			worldDirectionworldDirection.y = 0f;
			if (worldDirection.sqrMagnitude > 1f) worldDirection.Normalize ();
			Vector3 cameraForward = KickStarter.CameraMainTransform.forward;
			cameraForward.y = 0f;
			cameraForward.Normalize ();

			Vector3 cameraRight = KickStarter.CameraMainTransform.right;
			cameraRight.y = 0f;
			cameraRight.Normalize ();

			float forwardAmount = Vector3.Dot (cameraForward, worldDirection.normalized);
			float rightAmount = Vector3.Dot (cameraRight, worldDirection.normalized);

			return new Vector2 (rightAmount, forwardAmount);
		}

#if ENABLE_INPUT_SYSTEM
		public new void OnMove(InputValue value)
		{
			if (underACControl) return;
			MoveInput(value.Get<Vector2>());
		}

		public new void OnLook(InputValue value)
		{
			if(cursorInputForLook)
			{
				LookInput(value.Get<Vector2>());
			}
		}

		public new void OnJump(InputValue value)
		{
			if (underACControl) return;
			JumpInput(value.isPressed);
		}

		public new void OnSprint(InputValue value)
		{
			if (underACControl) { SprintInput (acCharacter.isRunning); return; }
			SprintInput(value.isPressed);
		}
#endif

	}
	
}
Advertisement