- Home /
Player Arm will not rotate when moving with Xbox Joystick
Hello,
My problem is I can't get my player's arm to move when a weapon is selected. I'm using an Xbox One controller and have the inputs in Unity. I can move the arm with the mouse and have it face the position the mouse is pointing at but I can't make it work with the controller.
My code to make the players arm move with mouse...
public void CanTurn()
{
Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Speed * Time.deltaTime);
}
I've looked at the API and many tutorials and and still nothing has worked. I thank anyone that stops by to look or helps.
Thank You.
I have fixed it... well almost it still not 100% the way I like it but it dose pretty much what I wanted it to do.
Here's the updated code...
public void CanTurn()
{
//Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
//float angle = $$anonymous$$athf.Atan2(direction.y, direction.x) * $$anonymous$$athf.Rad2Deg;
//Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
//transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Speed * Time.deltaTime);
//Xboxcontroller...
Vector2 shootingDirection = Vector2.right * -Input.GetAxis("Vertical Right") + Vector2.down * -Input.GetAxis("Horizontal Right");
float angle = $$anonymous$$athf.Atan2(shootingDirection.y, shootingDirection.x) * $$anonymous$$athf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Speed * Time.deltaTime);
}
Answer by Rati · Apr 17, 2019 at 08:02 PM
Use the pad axis instead of the mouse position.
there is some example here https://docs.unity3d.com/ScriptReference/Input.GetAxis.html