Answers for "Best rotation function to use"
http://answers.unity.com/questions/1321864/best-rotation-function-to-use.html
The latest answers for the question "Best rotation function to use"Answer by AurimasBlazulionis
http://answers.unity.com/answers/1321908/view.html
You have a few options.
1) Multiply the rotation by the specific quaternion. It would be really efficient in most cases, but would require you to do it in fixed update.
private Quaternion _rotation;
public float speed;
private float _speed;
public Quaternion rotation {
get {
if (_speed != speed) {
_speed = speed;
_rotation = Quaternion.Euler (0, speed * Time.fixedDeltaTime, 0);
}
return _rotation;
}
}
void FixedUpdate () {
transform.rotation = transform.rotation * rotation;
}
Or if you want to do it in Update, then you will need to call Quaternion.Euler every frame (which is not that good. You will only need speed variable. That is it.
void Update () {
transform.rotation = transform.rotation * Quaternion.Euler(0, speed * Time.deltaTime, 0);
}
Or you can use Quaternion.LerpUnclamped. It is really cool. The code would look like this:
private Quaternion _rotation;
public float rot;
private float _rot;
private Quaternion startRotation;
private float startTime;
public Quaternion rotation {
get {
return _rotation;
}
}
void Update () {
if (_rot != rot) {
startTime = Time.time;
_rot = rot;
startRotation = transform.rotation;
_rotation = Quaternion.Euler (0, transform.rotation.eulerAngles.y + rot / 3f, 0);
}
if (Time.time - startTime <= 1f)
transform.rotation = Quaternion.LerpUnclamped (startRotation, rotation, (Time.time - startTime) * 3f);
}
Sure you will need to change it. What it does, is when the target rotation changes, it creates a rotation Quaternion of the target rotation and divides the y target rotation by 3 so no the closes path is chosen.
Actually, other than these things (not even sure about the last one), Transform.rotate would work the best and simplest.Sun, 05 Mar 2017 16:43:27 GMTAurimasBlazulionis