x


how to smoothly rotate the character controller by 45 Degrees using the keyboard arrow keys?

in the same way as LEGO Star Wars The Quest for R2D2 game using the keyboard arrow keys

more ▼

asked Dec 07 '09 at 03:22 AM

jaspion gravatar image

jaspion
1 1 1 3

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

1 answer: sort voted first

there is not an special way for character controllers but you can rotate a transform smoothly easily. you should use coroutines for this.

C# code

IEnumerator RotateSmoothly(float deg)
{
float current; //object will rotate in this ammount in each frame
float rotated=0
while (rotated < deg)
{
current=30*time.deltaTime; //30 degrees per second
if (rotated+current>deg) current-=deg-rotated; //clamping
transform.rotate (current,0,0);
yield return 0; //wait one frame and execute the loop again
}
}

the code is written here and is not tested but it can take you the idea of doing things like this. this code works for values greater than zero but you can easily modify it to work with values less than zero.

more ▼

answered Dec 07 '09 at 05:30 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

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

x5098
x1047

asked: Dec 07 '09 at 03:22 AM

Seen: 2629 times

Last Updated: Dec 07 '09 at 04:01 AM