Hi everyone,
sorry for my English, I’m trying to learn it by myself.
I need help to create a c# script to make slide an object between two moving points.
PointA and PointB have attached a script which move them randomly in the scene.
In the image linked below in step 1 you can see the point A, the point B and the spawned object in the starting situation
In step two in the image linked above you can see my current situation whit the script below which is attached to spawned object:
private Transform pointA;
private Transform pointB;
void Update()
{
pointB = GameObject.FindWithTag ("PointB").GetComponent<Transform> (); //Constant search of pointB's position in the scene
float speed = -0.1f * Time.deltaTime;
transform.position = pointA.position + (poinA.position - pointB.position) * speed;
}
If the pointB are moving the spawned object doesn’t remains on the line between the two points.
In step 3 in the image you can see what I want: I need that the spawned object face to point B and constantly remains on the line between the two points while moving to poinB.
EDIT: I forgotten to say that the distance between the points is not always the same.
Thank you for any help you give me.