- Home /
Rotate object smoothly problem
I have object that can be in 2 positions that I have to change position smoothly init position is set (270,90,0) and when it is needed I have to rotate it to (270,-90,0) 180 deg
I tried this
rotateArm.transform.RotateAround(rotateArm.transform.position, Vector3.up, desired_angle * Time.deltaTime);//rotateArm is a child that I want to rotate
the problem is it rotate smoothly but not stoping (ovice)
so I tried slerp
public Quaternion initial = Quaternion.Euler(270f, 90f, 0f); public Quaternion finial = Quaternion.Euler(270f, -90f, 0f); Quaternion.Slerp(initial, finial, desired_angle * Time.deltaTime); //desired _angle it ether 1 or -1
non of them worked another question how can I find out at which position is the Arm set to? i.g. if arm is at 90 then go to -90 else go to 90
thank you
strong text
Answer by Tal770 · Jan 15, 2012 at 03:10 PM
Its a simple case if arm = 90 rotate smoothly to -90 can any one help on this?
I am a little confused here about what the problem is. Are you answering your own question? It could be very helpful if you maybe copy and paste the code so people can see if the problem is in the coding.
Answer by Serve_Hermans · Jan 18, 2012 at 08:01 PM
I would recommend to use the iTween library. It is free and I am using it myself in my game. There you can either call the RotateBy or RotateTo. So if you need your arm to rotate to -90 with regards to its original position you would you RotateBy. It takes parameters like the kind of rotation (lineair, easein/out etc), a delay, the duration, a callback function when finished etc. Very useful! The library is a plugin.
Example: iTween.RotateAdd(gameObject,{"amount":rotateAmount, "time":rotateTime, "easeType":rotateEase, "delay":rotateDelay, "loopType":rotateLoopType});