- Home /
Rotating a character with the joystick of the controller
I am currently working on a script to allow my character to move using the joystick on a xbox 360 controller. The character is moving along a plain and has the ability to move in any direction. I am trying to get my character to rotate the way that he is moving based on the orientation of the joystick. Is this possible?
Here is the code I am using to get it to move.
function Update () {
moveForward = Input.GetAxis("Vertical") forwardBack; moveRight = Input.GetAxis("Horizontal") leftRight;
moveForward = -Time.deltaTime; moveRight = Time.deltaTime;
character.transform.position.x += moveForward; character.transform.position.z += moveRight; }
The game is build for PC just using the xbox 360 controller. Not Developing for the xbox
Answer by AngryOldMan · Mar 31, 2011 at 03:16 AM
you need a third party plug in or the xbox dev tools from unity to get access to coding for xbox 360 (legally that is)
other solution is to get some 3rd party software that lets you map an xbox controller to actual keystrokes then mapping your controller to the specific keys your are using in your unity project. In order to get your xbox controller working with your computer you need a wired controller or a wireless adapter port for 360 to pc. the Wireless adapter port will let u sync 4 controllers.
And for future reference there is a button in your questions tool bar with a picture of binary code saying
101
010
highlight all your code and use that to format it so it can be seen in a lovely code box such as this
function NeatCodePlease()
{
Debug.Log ("format your question code properly")
}
This answer is irrelevant to the question asked. I have stated that the code works with a controller to move. I just want to know if it is possible to rotate the character based on the tilt axis of the controller.
1st of all you havn't asked anything about tilt control in your original post, sceondly unless you have some state of the art 360 controller it doesn't have tilt sensors. "I am trying to get my character to rotate the way that he is moving based on the orientation of the joystick." is very vague. you don't need to use a joystick coordinate at all you could just get your character to face your move direction nothing to do with your controller. So the answer wasn't irrelevant because you edited your question after I posted my answer, the fact is your question is too vague.still!
The edit was for the code thank you for noticing my question didn't change at all. Awesome now we are getting somewhere. See it seems the question was not too vague since you were able to answer it. So if you could explain the relevance of the original post again that would be great. If I already have it working then it that doesn't mean I need to be told what I need to get it to work. A simple explanation of how to do what I was trying to do would have sufficed.
you don't need to use a joystick coordinate at all you could just get your character to face your move direction nothing to do with your controller. what don't you understand about that?
That one sentence was all you needed to answer the question. Thanks