How to apply lerp into a transform base on adding translate vector?

So my code look something like this:

t.position = t.position + (ray.origin + (ray.direction * dist)) - headPosOnGround;

and i try to do something like this :

targetloc.position = t.position + (ray.origin + (ray.direction * dist)) - headPosOnGround;

t.position = Vector3.Lerp(t.position, targetloc.position, Time.deltaTime * speed);

however that give me an nullreferenceexception error, what did I do wrong here?

Null reference means you are trying to use an object that doesn’t exist. You just have to find out which object it is. Without seeing the rest of the code, I’m guessing either targetloc or t aren’t being assigned a value.

Try to find where in your code you are setting targetloc and t and make sure it’s actually being assigned something. For example, you might have a typo in a GameObject.Find(“object”) or maybe you forgot to assign t or targetloc from the inspector.

You could try learning how to use the debugger to step through your code and find where exactly the error is happening: Get Started with Visual Studio and Unity - Unity Learn