Move to object - distance?

The last thing this forum needs is another transform move question. Yet, here I go =)

I’m ‘warping’ through space to an asteroid belt. And then directly into the rocks and destroying the players ship (HA!). So I need to make a buffer distance to the destination point. I don’t think you will need the whole script to see where my problem is.

//get destination vectors and minus it by some distance
myTargetX = myTarget.position.x - bufferDistance;
myTargetY = myTarget.position.y - bufferDistance;
myTargetZ = myTarget.position.z - bufferDistance;

//this moves transform to location.
myTransform.position = Vector3.MoveTowards(myTransform.position, myTarget.position (myTargetX , myTargetY , myTargetZ), Time.deltaTime * speed);

I get the error [The member `UnityEngine.Transform.position’ cannot be used as method or delegate]…

Can anyone suggest where to look to solve this problem?

Thank you kindly!

EDIT: This is a fix as to my own error.

You’re using position as a method instead of Vector3 as an instantiation.


Vector3.MoveTowards(myTransform.position, Vector3(myTargetX , myTargetY , myTargetZ), Time.deltaTime * speed);

Should work. Unless you’re getting an error elsewhere for some unknown reason.

first off, you can simplify your target logic:

var newTarget : Vector3 = myTarget.position - Vector3(bufferDistance,bufferDistance,bufferDistance);

then this will work:

myTransform.position = Vector3.MoveTowards(myTransform.position, newTarget, Time.deltaTime * speed);

(or for C#):

Vector3 newTarget = myTarget.position - new Vector3(bufferDistance,bufferDistance,bufferDistance);

Anyway, this is the part which was not right:

“myTarget.position (myTargetX , myTargetY , myTargetZ)”

it should say

“Vector3(myTargetX , myTargetY , myTargetZ)”