- Home /
Smooth rotate use joystick
i have a game object that i want to rotate when player move the joystick to left and right. i use single joystick from standard asset mobile . i use
void Update(){
xposisi = GameObject.Find("Single Joystick").GetComponent<Joystick>().position.x ;
transform.eulerAngles = new Vector3(0,0, xposisi * 10); ;
}
but that rotate doesn't smooth. i need more smooth rotate. what should i do? thankyou for all respons and im sorry for my bad english
Answer by teslatron · Apr 24, 2014 at 09:25 AM
Try like this:
Quaternion eulerRot = Quaternion.Euler(0.0f, 0.0f, xposisi);
transform.rotation = Quaternion.Slerp(transform.rotation, eulerRot, Time.deltaTime * 10);
hmmm i have try this but my object doesn't rotate. what do you think?
wooow awesome. its work!! my object didn't rotate because that value is to small. i multiple xposisi like this. Quaternion eulerRot = Quaternion.Euler(0.0f, 0.0f, xposisi*50); and its rotate smoothly. Greaat answer!! thanks a lot!! wew, i have spend 3 days for fix it. hehe
if u are not busy, can u explain how does it work?, i only understand for a bit
Lerp and Slerp functions in unity is widely used for smoothing. Lerp is used for linear interpolated situations, Slerp is used for spherically interpolated (usually rotations).
For your situation, if you set your rotation directly, your rotation will be sharp and crude. (sometimes that is what we want) The key is we don't set the rotation directly, but we set to our target rotation by time. The longer it takes, the better its smoothed.
You better check this tutorial out: http://unity3d.com/learn/tutorials/modules/beginner/scripting/lerp
Also these: https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Slerp.html http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Slerp.html
Your answer

Follow this Question
Related Questions
How to smoothly rotate object in direction of analog joystick? 1 Answer
Choppy rotation of character around y-axis 1 Answer
Rotation - Simple Question 0 Answers
Rotate smoothly an object when key is up 0 Answers
Smooth reset rotation problem 1 Answer