I've found a Slerp/Lerp is more complex than it originally seems.
First of all, your line `transform.LookAt(target)` will instantly snap your object's Z-axis as looking toward that object with no transition effect. That may explain the first spaz motion.
Now for the Slerp. This is how I do it with a `Mathf.Lerp` function, which should work similarly.
float t = 0.0F;
float hitPoints = 0;
float maxHitPoints = 100;
float buildTime = 30.0f; //Seconds
void Update() { //Or FixedUpdate if you want
if ( hitPoints < maxHitPoints ){
t += Time.deltaTime;
hitPoints = Mathf.Lerp(0, maxHitPoints, t / buildTime);
}
}
Every time the `Quaternion.Slerp` is called, `transform.rotation` is changing. The next time `Quaternion.Slerp` is called, it uses a different `transform.rotation` to calculate with.
You want to try and eliminate the variables that change during the calculation if you want a smooth, linear transition.
i had both a LookAt and the Slerp with the other LookAt , so i removed the first line and its ok
also it went backwards but i found the problem. it was (transform.position-target) while it should be (target-transform.position)