3DText - Translate towards Camera

I have an ImageTarget and when the target is detected, I am showing a 3DText. I want this text to start at the ImageTarget and move towards the Camera.

Let’s say I have the camera at a distance of 50 units and the target is at 0 units. When the image is detected, I want the text to start at 0 and with an interval of 5 units, move towards the camera and when it reaches the camera (45 units or 50 units), the text should stop moving.

Can someone help me with this? I am pretty new to Unity…

Thanks in advance…

Hi Vamischalla

Your first step is to determine the direction the text needs to move in:

Vector3 direction = (cameraPosition - textPosition).normalized;

Now you need to multiply the direction by the speed you want the text to move, and the speed of the game:

Vector3 velocity = direction * 5.0f * Time.deltaTime;

Finally you can add the velocity onto the position of the text:

textGameObject.transform.position += velocity;

After you’ve performed the addition you can do a test to see if you have reached the target distance yet.