- Home /
Determining tile-based direction from controller analogue input
Hi there
The game I am making is tile based and the movement system I want to implement involves the player being able to move to any of the 8 tiles surrounding the current tile. I want to do this using the left anologue controller input.
So far I have a working version but it doesnt feel right. By this I mean, sometimes I move the anologue stick to the bottom left and it instead goes left or i move it top right and and it instead goes right. Ofcourse if I concentrate real hard I can be 100% accurate but I movement to feel effortless.
The current way Im doing it is as follows:
Vector3 direction = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if (direction.x <= -0.8f) //left
{
if(direction.z < 0.5 && direction.z > -0.5)
{
Debug.Log ("Left");
}
}
Here I'm getting the direction input from the controller and storing it in a Vector3. Then I look at the X and Z values of that vector3 and determine which direction it should be based on whether those values fall within a certain range.
Is there a better or more built in way of doing this? If not, are there any recommend ranges for the values of the controller input that should be used to determine which of the 8 directions it should go?
Thanks in advance!