Can anyone please tell me what I am doing wrong:
Evening Dan,
what is the expected outcome? or what are you looking to achieve?
looking at the transform.translate, there are several overloads for this, but ultimately it takes a Vector3 for how far to translate an object and an optional parameter for where the translation is relative to ( self or worldspace)
now, i’ve noticed that you are using time.deltatime, but you are using within the FixedUpdate() method.
since Update() is called every frame, the time between each update can vary slightly, so using time.deltatime gives the time in seconds between each frame draw, or update.
but
FixedUpdate() is called at each physics timestep and is a set via the physics timestep interval, so basically a fixed timestep.
time.deltatime used from within Update() returns the time between frame draws.
time.deltatime used within FixedUpdate() will return the physics timestep Time.fixedDeltaTime, not the time between frames (as the compiler assumes the context).
Time.fixedDeltaTime API
As a general rule, use Update for translations, rotations etc and FixedUpdate for physics Forces etc
IMO I would possibly recommend moving this into Update()
are you using the Lerp, or just the translation?
I want an object to lerp from one destination to another, but I have not got it working.
I use FixedUpdate();
Thanks.
Sound Dan.
I’ll get a look tomorrow before i head off for work, see what I can do.
Lerping is a funny one as its often mistaken.
it takes a start and end position, however the time parameter is a position between 0 and 1, ie the percentage of how far it should be between 0 (start) and 1 (end) at a certain time.
Morning Dan,
Ive had a little play around this morning, heres what I have for lerping between two Vector3 positions.
using UnityEngine;
using System.Collections;
public class LerpToPosition : MonoBehaviour {
public float lerpTimeInSeconds = 3f; // time in seconds to get to its destination
public Vector3 endPosition; // end position to lerp to
private Vector3 startingPosition; // note of the start position
private float t = 0f; // to note the transition time
void Start () {
startingPosition = this.transform.position;
}
void Update () {
// need to get the float t position between 0 and 1 based on lerptime duration
t += 1/lerpTimeInSeconds * Time.deltaTime;
// now move the object
this.transform.position = Vector3.Lerp(startingPosition, endPosition, t);
// DELETE BELOW AFTER TESTING //
// this bits just for testing, so it will go back and fore between the points
if( t > 1f)
{
t = 0f;
Vector3 temp = startingPosition;
startingPosition = endPosition;
endPosition = temp;
}
}
}
Ive got to leave this morning, away back offshore for a week, hope you get it working the way you want.
if i might suggest something it would be, Vector3.MoveTowards();
might be a helpful function, since Lerping is basically timebased, while movingtowards is distance based.
hope this helps.
(the correct way of lerping is just like OboShape said.