This script locks the player's movement direction while jumping / in mid-air. It is intended for Direct or First Person movement methods, as it works by locking the "Horizontal" and "Vertical" input axes to their values when the player was last on the ground.
To use it, create a new C# script named LockJumpDirection.cs, paste the code below into it, and attach it to a GameObject in your scene:
using UnityEngine;
using System.Collections;
using AC;
public class LockJumpDirection : MonoBehaviour
{
private float lastGroundedHorizontalValue;
private float lastGroundedVerticalValue;
private void Start ()
{
KickStarter.playerInput.InputGetAxisDelegate = MyGetAxis;
}
private float MyGetAxis (string axisName)
{
float inputValue = Input.GetAxis (axisName);
if (KickStarter.stateHandler.IsInGameplay ())
{
if (axisName == "Horizontal")
{
if (KickStarter.player.IsGrounded ())
{
lastGroundedHorizontalValue = inputValue;
}
else
{
return lastGroundedHorizontalValue;
}
}
else if (axisName == "Vertical")
{
if (KickStarter.player.IsGrounded ())
{
lastGroundedVerticalValue = inputValue;
}
else
{
return lastGroundedVerticalValue;
}
}
}
return inputValue;
}
}