Adventure Creator Wikia
Advertisement

By default, Direct-controlled running occurs when the user presses an input named either "Run" or "ToggleRun". This script causes running to instead be based on whether or not the user presses the same directional input twice in quick succession.

To use it:

  1. Set your game's Movement method to Direct
  2. If defined, remove the inputs Run and ToggleRun from your Project -> Input settings.
  3. Create a new C# script named DoubleTapRunning, and paste in the code below
  4. Attach the new Double Tap Running component to an object in the scene

DoubleTapRunning.cs:

	using UnityEngine;
	using AC;

	public class DoubleTapRunning : MonoBehaviour
	{

		private float timeSinceLastInput;
		private Vector2 lastInputDirection;
		private bool hadNoInput;
		private bool run;

		private const float doubleTapTime = 0.5f;
		private const float minInput = 0.01f;
		private const float minDotProduct = 0.9f;

		void Start ()
		{
			KickStarter.playerInput.InputGetButtonDelegate = GetButton;
		}

		bool GetButton (string inputName)
		{
			if (inputName == "Run") return run;
			try
			{
				return Input.GetButton (inputName);
			}
			catch {}
			return false;
		}

		void Update ()
		{
			Vector2 moveInput = KickStarter.playerInput.GetMoveKeys ();
			bool hasInput = moveInput.sqrMagnitude > minInput;

			if (hasInput)
			{
				if (hadNoInput)
				{
					float timeGap = Time.time - timeSinceLastInput;
					if (timeGap < doubleTapTime)
					{
						float dotProduct = Vector2.Dot (moveInput.normalized, lastInputDirection);
						if (dotProduct >= minDotProduct)
						{
							run = true;
						}
					}
				}

				timeSinceLastInput = Time.time;
				hadNoInput = false;
				lastInputDirection = moveInput.normalized;
			}
			else
			{
				hadNoInput = true;
				run = false;
			}
		}

	}
Advertisement