x


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.
more ▼

asked Apr 26 '11 at 08:06 AM

Graeme P gravatar image

Graeme P
48 18 21 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 26 '11 at 09:08 AM

Cyb3rManiak gravatar image

Cyb3rManiak
1.6k 1 4 17

Thanks so much for the reply, i havent quite got it working yet, but with some tweaking itl be perfect.

Thanks again!

May 02 '11 at 07:44 AM Graeme P
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2248
x706
x549
x329
x62

asked: Apr 26 '11 at 08:06 AM

Seen: 1815 times

Last Updated: Jul 18 '11 at 09:16 PM