- Home /
The question is answered, right answer was accepted
smooth rotate help
i have a script when you collide with an object and press a key it rotates. however it rotates instantly and i want it to do i smoothly. here is my script:
function OnTriggerStay(trigger : Collider) {
if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E)) {
transform.Rotate(0, 10, 0 * Time.deltaTime);
}
}
how would i make it rotate smoothly?
thanks
First it might help if you weren't multiplying Time.deltaTime by zero. What happens when you multiply a number by 0?
Answer by DaDonik · Nov 10, 2014 at 10:50 AM
function OnTriggerStay(trigger : Collider)
{
if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E))
{
transform.Rotate(0.0f, 10.0f * Time.deltaTime, 0.0f);
}
}
If you need it slower, just replace 10.0f with a lower value.
at the moment it moves in sharp jolts "0,0,0" are just how much it rotates on an axis. i would like it to rotate smoothly
We know. But by multiplying the rotation by deltaTime, which is the time in seconds since the last frame, the motion becomes framerate independent. This makes the motion "smooth". If this isn't what you're looking for, then it would be helpful if you could clarify what you mean by "smooth", because it's a very vague term.
Oh well, i wasn't thinking before posting, sorry. One way you can achieve what you want to do is by setting a variable inside the OnTriggerStay and then rotate your object in the Update function. Like so:
var Rotate$$anonymous$$e = false;
var RotateSpeed = 10.0f;
function Update()
{
if (Rotate$$anonymous$$e == true)
{
transform.Rotate(0.0f, RotateSpeed * Time.deltaTime, 0.0f);
}
}
function OnTriggerStay(trigger : Collider)
{
if ((trigger.gameObject.tag == "Player") && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
{
Rotate$$anonymous$$e = true;
}
else
{
Rotate$$anonymous$$e = false;
}
}
RotateSpeed will be in degrees per second in that case.
I'm not using Unityscript normally, so i'm not 100% sure thats all correct, but it should be.
all i had to do was tweak one thing and it worked
cheers
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Door rotate on hinge 1 Answer
Animation spins wildly after completed 0 Answers