I want an object to follow another object just like the way it follows it when it's parented to it, but smoothly and only in the x and z axis.
Here's my code so far:
distanceX = player.position.x - transform.position.x; distanceZ = player.position.z - transform.position.z; transform.position = Vector3.Lerp(new Vector3(transform.position.x, transform.position.y, transform.position.z), new Vector3(transform.position.x + distanceX, transform.position.y, transform.position.z + distanceZ), Time.deltaTime);
Now the problem is that it goes way too close to the player and ignores the current distance.
If you got any questions please don't hesitate to ask.
Thank you for your time!
I'm not looking to make the object go to the target's position, just to follow it and keep the distance, just like it does when it's parented to that object, but smoother movements.
Looks like I have made a mistake when I said that I wanted to keep the same distance between the two objects. What I actually meant was that I want the offset to be the same. I apologize to anyone who I confused or wasted their time! P.S. I'm still looking forward to finding a fix for my issue.