SmoothDamp function just teleports the object to the target position

I want to make it so when I press the play button, the camera smoothly transitions from its current position, to the target position using the SmoothDamp function. But instead the camera just snaps to somewhere close to the target position (i.e the target position is 0, 0, -1 but the camera goes to 0.0011, 0.2716, -0.9988)
this method is called when I click the play button:

private Vector3 velocity = Vector3.one;
public float smoothTime = 0.3f;

public void CameraTransition()
    {
        Vector3 positionTarget = new Vector3(0, 0, -1);
        transform.position = Vector3.SmoothDamp(transform.position, positionTarget, ref velocity, smoothTime * Time.deltaTime);

    }

Think about the velocity variable as an internal state of the SmoothDamp. It’s passed by reference because the SmoothDamp reads and also writes to it. It tries to gradually accelerate and decelerate when transform.position is reaching the positionTarget. The problem I see in your code that you are initializing the velocity variable to value Vector3.one, which means the SmoothDamp thinks from start that your target position is already moving fast towards the target, therefore it’s possibly reaching it instantly (depends on the actual distance). So just try to initialize it to Vector3.zero instead.

it worked, thanks! :slight_smile: