x


Steering Wheel Problem

Hey

I have this code to making a steering wheel:

var rotationSpeed : float = 100.0;

function Update () {

        var rotation : float = Input.GetAxis("Horizontal") * -rotationSpeed * Time.deltaTime;   

        transform.Rotate(0, 0, rotation);
}

It is working ok but I need the steer to comeback to the original position when I stop pressing the arrow keys. How can I do that?

I tried using Quaternion.Slerp but I can't define the original position to comeback to.

Thanks for any help

more ▼

asked May 06 '11 at 03:41 PM

maveryck21 gravatar image

maveryck21
239 29 32 44

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

2 answers: sort voted first

Create a quaternion variable to store the default rotation in local space on awake or start, then you can lerp/slerp just fine from transform.localRotation to that variable.

more ▼

answered May 06 '11 at 06:39 PM

Alec Slayden gravatar image

Alec Slayden
1.2k 1 4 15

Yeah you are right, I was using transform.rotation instead of the localRotation, that was the error. Thanks

May 07 '11 at 03:54 PM maveryck21
(comments are locked)
10|3000 characters needed characters left

My problem is solved thanks to Alec Slayden, here is the code:

var rotationSpeed : float = 100.0;
static var origRotation : Quaternion;

    function Awake () {

        origRotation = transform.localRotation;
    }

    function Update () {

            var rotation : float = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;   

            transform.Rotate(0, rotation, 0);

            transform.localRotation = Quaternion.Slerp(transform.localRotation, origRotation, Time.deltaTime);
    }
more ▼

answered May 07 '11 at 03:56 PM

maveryck21 gravatar image

maveryck21
239 29 32 44

(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:

x5051
x415

asked: May 06 '11 at 03:41 PM

Seen: 1323 times

Last Updated: May 06 '11 at 03:41 PM