- Home /
Why won't the Right stick of a Xbox 360 pad rotate my character?
Hiya guys! I am making a 2d Twin Stick Shooter. I have managed to make the player move around with the right stick just fine, however the rotation in Z axis is not working. If anyone could help that would be fantastic Thank you very much! I have attached a screenshot of my InputManager and have attached my code too. using UnityEngine; using System.Collections.Generic;
public class XboxController : MonoBehaviour {
public float moveSpeed = 1.0f;
// Update is called once per frame
void Update () {
Controls();
}
void Controls()
{
float horizontal = -Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float Vertical = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
float RightHorizontal = Input.GetAxis("RHorizontal");
float RightVertical = Input.GetAxis("RVertical");
Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), +Input.GetAxis("Vertical"), 0);
Vector3 moveAngle = new Vector3(0, +0, 45);
transform.position += moveDirection * moveSpeed * Time.deltaTime;
float angle = Mathf.Atan2(RightHorizontal, RightVertical) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
}
}
Answer by GrayMatterTutorials · Jan 09, 2017 at 08:09 AM
@jayp246, I'm not sure whether or not you tested whether the RHorizontal or RVertical has value change at all, but I recommend starting with that. Just throw RHorizontal into a Debug.Log statement and see if it goes between 0 and 1 when moving the Joystick. If so, let me know. Likewise, I totally recommend using XInputDotNet for your Xbox Controller inputs! It's really nice and sets everything up on it's own so you don't have to. Better yet, it supports up to 4 controllers at a time. Here's the link: https://github.com/speps/XInputDotNet
Your answer
Follow this Question
Related Questions
Vector3.MoveTowards doesnt work 1 Answer
Instantiated object not showing in scene or hierarchy 2 Answers
re-entering on the opposite side? 1 Answer
Side scroller spawns at different Y 1 Answer