Vector3.Lerp is not reacting, pls help (simple script)

public Transform target;
public float speed;
public Vector3 offset;

private void FixedUpdate()
{
    Vector3 DesiredPosition = target.position + offset;
    transform.position = DesiredPosition;
    Vector3 Smoothing = Vector3.Lerp(transform.position, DesiredPosition, speed);
    transform.position = Smoothing;

}

Changing the smoothing(speed) doesn’t effect the smoothing(speed) let a lone getting a smoothing. I made a simple cube with a movement script and a camera with a camera script^^. Only when I would change the cube script to update and camerascript to fixed update I would get some smoothing but then again changing the smoothing(value) didn’t affect it and it glitched. I have a MacBook Pro and iam running the latest version of Unity. The weird thing is that I literally copied the scripts from Youtube_Unity and Youtube_Brackeys but they didn’t work I tried a lot am I missing something? (By the way there was even a point where my camera flew the opposite way in a straight line of what it should follow… )

You have a few mistakes there Firstly,


  1. unless your transform has a rigidbody attached, you should really be updating its position in Update as FixedUpdate is for physics instructions.
  2. You are setting the transform’s position to your desired position before you even start the lerp.
  3. It looks like you are confused over the 3rd parameter for the lerp method.

The 3rd parameter of the lerp method which Unity calls time could also be called percent. It is not how long the lerp will take, it is a percentage from the startpoint to the endpoint. The method uses a range of 0 - 1 for this. So 0 would return the start point (1st parameter) and 1 would return the endpoint (2nd parameter). The method also clamps the time parameter to 1 so even if you put 1000 in there, it would still return the endpoint.


This code should do what you wish;

    private void Update()
    {
        var DesiredPosition = target.position + offset;
        transform.position = Vector3.Lerp(transform.position, DesiredPosition, Time.deltaTime * speed);        
    }

Although I would recommend using MoveTowards instead

    private void Update()
    {
        var DesiredPosition = target.position + offset;
        transform.position = Vector3.MoveTowards(transform.position, DesiredPosition, Time.deltaTime * speed);        
    }

Thank you for ur reply, but it didn’t worked… I copied ur script (and MoveTowards) but the camera just followed the target without smoothing. Since I am working on a project this is really annoying. This script is from Unity, is this also rong? (target is moving in fixed update and has a Rigidbody). Lastly what value do I need to paste in smoothing to be sure it really should smooth? Do I need to make a quick video cus it is still not working so u can see everything.


public Transform target;
public float smoothing = 5f;
Vector3 offset;


Void Start ()
{ offset = transform.position - target.position;}


Void FixedUpdate()
{ targetCamPos = transform.position + offset;
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing);
}