- Home /
How to edit Direction Angle using GetAxis 2.5D 8 direction movement
I currently have a basic 8 directional movement like this -
This is my current Code
Animator anim;
public float speed = 3f;
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
float input_x = Input.GetAxisRaw("Horizontal");
float input_y = Input.GetAxisRaw("Vertical");
bool isWalking = (Mathf.Abs(input_x) + Mathf.Abs(input_y)) > 0;
anim.SetBool("isWalking", isWalking);
if (isWalking)
{
anim.SetFloat("x", input_x);
anim.SetFloat("y", input_y);
transform.position += new Vector3(input_x, input_y, 0).normalized * speed * Time.deltaTime;
}
}
}
Which works fine, but i need to change the angle of North West, North East, South West , South East to something like this, as the Character currently gradually moves into the wall when running in those directions
How can i achieve this while keeping my GetAxis controller support?
Thanks.
Answer by Bunny83 · Jul 21, 2017 at 01:21 PM
This looks like a classical aspect ratio distortion. All you need to do is multiplying your "x" input value by tan(56.66). The normal case would be tan(45) which is "1". tan(56.66) is about "1.52".
float input_x = Input.GetAxisRaw("Horizontal") * Mathf.Tan(56.66f * Mathf.Deg2Rad);
float input_y = Input.GetAxisRaw("Vertical");
Your answer
Follow this Question
Related Questions
Move infinitely in targeted direction 3 Answers
Enemy AI Movement one axis at a time (8 directional - 2.5d) towards player/target 2 Answers
Tracking HTC Vive Controller Motion Direction? 1 Answer
Need player to walk in random direction 2 Answers
4 way direction movement using a Character Controller. 1 Answer