x


player lean - doesn't get back to previous position

Hey there! I'm trying to make a script, when player holds q button, i move him a little bit and rotate camera (z axis). However, script works, but when i'm holding q, and rotate player for example, 180 degrees, player doesn't get back to start position, but rotates even more. Here's my code:

if(Input.GetButton("LeanLeft")) {
    isLeaning = true;

    if(currentLean < leanSize) {
        transform.Translate(leanSpeed * Time.deltaTime, 0, 0);
        if(leanSize > 0.6) {
           transform.Rotate(0, 0, leanSpeed * Time.deltaTime * -1 * leanAngle);
        }
        currentLean += leanSpeed * Time.deltaTime;
    }
}

if(Input.GetButtonUp("LeanLeft")) {
    isLeaning = false;
}

if(currentLean > 0.01 && (!isLeaning)) { transform.Translate(leanSpeed * Time.deltaTime * -1, 0, 0); transform.Rotate(0, 0, leanSpeed * Time.deltaTime * 1 * leanAngle); currentLean -= leanSpeed * Time.deltaTime; }

Here is result, what happens if i rotate 180 degrees when leaning:

alt text

Thank you for your time!

bug.png (62.1 kB)
more ▼

asked Apr 10 '12 at 04:56 PM

devlab_lt gravatar image

devlab_lt
53 2 3 6

cool you would use an else statement or get key up to set rotation to 0,0,0

Apr 11 '12 at 12:16 AM garner
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Nevermind, i fixed that bug when using animation.

more ▼

answered Apr 10 '12 at 11:45 PM

devlab_lt gravatar image

devlab_lt
53 2 3 6

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

x2171
x7

asked: Apr 10 '12 at 04:56 PM

Seen: 446 times

Last Updated: Nov 20 '12 at 12:30 PM