Hi,
Trying to use the Locomotion starter pack script from the Asset store to try and make my own fully functioning controller. I have one problem though, the script seems to always be making my character move forwards i.e. going from 0 to 6 speed float (Mecanim) when I press S as well as W. I can’t really figure out what part I am missing.
public class JoystickToEvents : MonoBehaviour
{
public static void Do(Transform root, Transform camera, ref float speed, ref float direction)
{
Vector3 rootDirection = root.forward;
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 stickDirection = new Vector3(horizontal, 0, vertical);
// Get camera rotation.
Vector3 CameraDirection = camera.forward;
CameraDirection.y = 0.0f; // kill Y
Quaternion referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);
// Convert joystick input in Worldspace coordinates
Vector3 moveDirection = referentialShift * stickDirection;
Vector2 speedVec = new Vector2(horizontal, vertical);
speed = Mathf.Clamp(speedVec.magnitude, -1, 1);
if (speed > 0.01f) // dead zone
{
Vector3 axis = Vector3.Cross(rootDirection, moveDirection);
direction = Vector3.Angle(rootDirection, moveDirection) / 180.0f * (axis.y < 0 ? -1 : 1);
}
else
{
direction = 0.0f;
}
}
}
Is there a line of code im missing in order to get my WalkBack state to start working correctly? Thanks!
John