Hello,
How could I rotate my object (Square) in 45degree, but I would like to
rotate from 0 to 45 slowley instead of sudden change? How could I do
it?
C#
transform.eulerAngles = new Vector3(45, 0, 0);
Thank you for your help
Aprial
Hello,
How could I rotate my object (Square) in 45degree, but I would like to
rotate from 0 to 45 slowley instead of sudden change? How could I do
it?
C#
transform.eulerAngles = new Vector3(45, 0, 0);
Thank you for your help
Aprial
I think you are looking for a Lerp.
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html
This allows you to interpolate between 2 vectors over a given time. You can also look up Mathf which has some functions for lerping with ints or floats.
With a single float value you can use:
Mathf.MoveTowardsAngle - linearly move one value to another by maxDelta (speed).
Mathf.LerpAngle - same, but using percent-like value (usually target time). with “0” as “t” you will get base value, with “1” - target value.
With a Vector3 value:
Vector3.MoveTowards - same as Mathf.MoveTowards.
Vector3.Slerp - same as Mathf.Lerp.
Vector3.SmoothDamp - smoothly move one vector to another with spring-like damping.
[SerializeField]
private float smoothTime = 1; // time to target
public Vector3 target = new Vector3(45, 0, 0);
private Vector3 vel; // this one for SmoothDamp function
void Update() {
transform.eulerAngles = Mathf.SmoothDamp(transform.eulerAngles, target, vel, smoothTime);
}
Thank you,