Hi guys,
I want to use Mathf.SmoothDampAngle to rotate an object which have to follow the given angle. I works well when the given degree is from 0 to 90 and from 180 to 360, but when it turns from 91 to 179 the target object’s rotation is totally messes out.
this is my code:
void Update () {
var damp = Mathf.SmoothDampAngle(transform.eulerAngles.x, /*Normalise(*/gc.getTravelledDeg()/*, 90, -90)*/ + 10.0f, ref smoothVelocity, 0.5f);
transform.rotation = Quaternion.Euler(damp, 0, 0);
}
//Normalizes any number to an arbitrary range
//by assuming the range wraps around when going below min or above max
float Normalise( float value, float start, float end )
{
float width = end - start; //
float offsetValue = value - start; // value relative to 0
return ( offsetValue - ( Mathf.Floor(offsetValue / width ) * width ) ) + start ;
// + start to reset back to start of original range
}
I have tried to normalise the angle. I only got a partial result when I used the normalisation from 90 to -90, but it is not what I want. I really don’t know what is the problem with my code. Please, help me…