- Home /
Smoothly transform forward ?
Hi I'm currently trying to update the transform of my game object with that Vector3.Lerp.
Before trying to implement that Lerp effect my transform scritp was this one :
ship.transform.Translate(Vector3.forward * currentSpeed * Time.deltaTime);
Now I tried this but that not work :
public Vector3 destination;
private void Start()
{
Photonview = GetComponent<PhotonView>();
if (Photonview.isMine)
{
destination = transform.position;
}
}
private void Update()
{
destination += ( Vector3.forward * currentSpeed );
ship.transform.position = Vector3.Lerp( Vector3.forward, destination, 0.5f * Time.deltaTime );
}
Any idea please ?
Answer by gordiri · Jan 26, 2018 at 02:26 PM
You are using Lerp wrong. Lerp interpolates between first and second parameters. You should pass as first parameter ship.transform.position instead Vector3.forward
Yep I can see that Lerp effect works but now my GameObject which have the script attached to is moving to the left.
It's probably because the destination var, is there any way to says " ship.destination += his destination " ?
Thank !
It can move left bc you are using Vector3.forward which is always (0, 0, 1). I think you should use
transform.forward
That's still using Lerp wrong. You shouldn't pass in Time.deltaTime as the third parameter. The third parameter is a value between 0F and 1F, and Lerp (a, b, x)
returns a if x == 0, b if x == 1, and a weighted value between a and b if x is between 0 and 1. $$anonymous$$eanwhile, Time.deltaTime returns the amount of time the last Update loop took; if your game is running at 60 frames per second, it'll return roughly (1F/60F), making it pointless to use with Lerp.
Your answer
![](https://koobas.hobune.stream/wayback/20220612151329im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I rotate the transform by a specific angle at a certain speed? 2 Answers
Instantiated object's transform changes according to parent object's rotation 1 Answer
Children's position going haywire (Unity bug?) 1 Answer
Make a GameObject a Child of What it Collides With 2 Answers
Adding data to a set of transforms 1 Answer