- Home /
Xbox movement issue
Hi there, I am a noob at unity and I just started xbox programming in unity and I watched this tutorial
The issue is that my character continuously moves forward after I touch a joystick and the camera can only move up and down, say if you touch the Camera joystick to the left or right it will not move. I would like it so if you touch the joystick to the right or left the camera will move in that direction. Sorry if that's confusing. Here's the code from the tutorial.
pragma strict
var speed = 10;
var rotatespeed = 5;
var cam : Transform;
function Update () {
var amtToRotate = rotatespeed * Input.GetAxis("VerticalRight") * Time.smoothDeltaTime;
var amtToRotateVert = rotatespeed * Input.GetAxis("HorizontalRight") * Time.smoothDeltaTime;
var amtToMove = -speed * Input.GetAxis("Vertical") * Time.smoothDeltaTime;
var amtToSideStep = speed * Input.GetAxis("Horizontal") * Time.smoothDeltaTime;
transform.Translate(Vector3.forward * amtToMove);
transform.Translate(Vector3.right * amtToSideStep);
transform.Rotate(Vector3.up, amtToRotate);
cam.Rotate(Vector3.left, amtToRotateVert);
}
heres the buttons in the input manager
I am using a mac OSX, I don't know if that makes a difference.
Thanks I appreciate all the help for I am a noob :)
screen shot 2014-02-14 at 9.17.44 pm.png
(61.4 kB)
screen shot 2014-02-14 at 9.24.40 pm.png
(60.7 kB)
Comment
Answer by erick_weil · Feb 15, 2014 at 03:51 AM
add a rigidybody to your character and use this code to move:
var speed = 10;
var rotatespeed = 5;
var cam : Transform;
function Update () {
var amtToRotate = rotatespeed * Input.GetAxis("VerticalRight") * Time.smoothDeltaTime;
var amtToRotateVert = rotatespeed * Input.GetAxis("HorizontalRight") * Time.smoothDeltaTime;
var amtToMove = -speed * Input.GetAxis("Vertical");
var amtToSideStep = speed * Input.GetAxis("Horizontal");
// to move foward
transform.rigidbody.velocity.z = (amtToMove *transform.forward.z);
transform.rigidbody.velocity.x = (amtToMove *transform.forward.x);
// to move at side
transform.rigidbody.velocity.x += (amtToSideStep*transform.right.x);
transform.rigidbody.velocity.z += (amtToSideStep*transform.right.z);
transform.Rotate(Vector3.up, amtToRotate);
cam.Rotate(Vector3.left, amtToRotateVert);