Control object (character) rotation with 360 analogue.

Hi,

I have a game where you are in a sub-sea environment, and fly about in a ship.

Im controling the ship via an xbox 360 controller, using this..

var moveSpeed:float = 1.0;
var turnSpeed:float = 1.0;
var climbSpeed:float = 0.2;
var bouancy:float = 1.0;

function Update ()

{

var DepthControl = Input.GetAxis("Depth");

var horizontalSpeed = Input.GetAxis("Horizontal");

var verticalSpeed = Input.GetAxis("Vertical");

transform.position += transform.forward * verticalSpeed * moveSpeed * Time.deltaTime;

transform.position += transform.right * horizontalSpeed *moveSpeed * Time.deltaTime;

transform.position += transform.up * DepthControl * climbSpeed * Time.deltaTime;

transform.position -= transform.up * bouancy * Time.deltaTime;

}

And i have the other analogue stick controlled by the 'mouse look' standard script attached to the object. As well as the triggers on the back for climbing and decending.

It all looks fairly well so far, but im stuck with how to get the object to tilt when it slides side to side using my 'horizontalSpeed' axis.

i have tried adding

transform.Rotate(Vector3.right, Time.deltaTime);

to it, and other variations, but nothing seems to make it rotate.

Is there some easier way of doing this? - or have i just failed to understand something.

Could the mouse look be canceling out my rotation values?

Any advice would be appreciated, thanks!

  • Graeme.

I think you're right, and in your case the mouse look script is canceling your rotation. To start I would try and disable the mouse look scripts and try and make the tilting work.

After that look in the mouse look script and see where it updates transform.rotation or transform.localRotation.

I have a MouseLook script here, but I'm not sure it's the original one. Anyway, there should be a line similar to

transform.localRotation = originalRotation * xQuaternion * yQuaternion

Each frame the local rotation is reset to the value set here, so if your script happens to run before the mouse look script - you won't see the tilt. Script run order is pretty random unless you make some steps to sync them.

Try and adding your tilt right after this line.

I would even edit this line. Maybe add a zQuaternion that will hold the tilt rotation. Just remember that in that case - you can't really use transform.Rotate since it's a method that rotates the object X degrees EACH FRAME. I would create the necessary quaternion just like the xQuaternion and the yQuaternion are created.