I’ve been looking around and I’ve seen Lerp placed in Update and in LateUpdate. Trying to optimize my code but I’m new to this coding, Does it matter were I Lerp the position/rotation of a gameObject? Some guidance or a point in the right direction would be greatly appreciated.
The following code is from: http://www.cratesmith.com/archives/183 and http://answers.unity3d.com/questions/23566/how-to-get-an-object-to-follow-another-object-at-a.html
-
public void Update() {
// Just interpolate values each frame
currentTrajectory = SetTrajectory(Vector3.Lerp(currentTrajectory,
updatedTrajectory,
Time.DeltaTime*trajectoryBlend); } -
function LateUpdate()
{
thisTransform.position.x = Mathf.Lerp( thisTransform.position.x,
target.position.x + xOffset,
Time.deltaTime * smoothTime);
thisTransform.position.y = Mathf.Lerp( thisTransform.position.y,
target.position.y + yOffset,
Time.deltaTime * smoothTime);}
Here’s a snippit of my code, its on the main camera.
void Update()
{
appliedSpeed = Time.deltaTime * damp;
}
void LateUpdate()
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0,0,angle), appliedSpeed);
}
I split them up because I thought one could be calculated a bit less then the other. Not sure if this is a good thing or if I should keep them both in the update function.
The reason why I’m asking is because when I build my game to an Android device (Galaxy S2/S3) it’ll be running smoothly but then the camera will cut/jerk in a random direction, the problem isn’t present when the game builds on my PC and I’ve got no idea why its doing it :[ Halp…
Thank you very much ^___^
– MrCow