I’m not sure where you got this from, or what you are trying to do, but several things make my head clang !
First thing was brought up in a below comment : InvokeRepeating(‘Update’,1,1);
(The syntax is wrong, this should be written InvokeRepeating(“Update”,1,1); , use “Quotation marks”) - as corrected by Eric, you can use ’ and " to denote strings. Ignore this line!
Now, I havn’t tested this, but Update runs every frame. To me this line would just invoke Update every second even while Update loops normally
You can set the time-step of FixedUpdate if that is required; 1/ any physics should be done in FixedUpdate , and 2/ the timestep can be modified in the editor.
You really should just make another function and use that :
InvokeRepeating( "MyMoveFunction" , 1.0, 1.0 );
function MyMoveFunction() { // move here }
Now to the objects, why are you typecasting as Rigidbody? Nothing in your script uses velocity, rather it uses objects’ transforms so why dont you just typecast and store references to the objects’ transforms instead.
I have never used MoveTowards but a quick search suggests that it is like lerp. So I guess you are trying to lerp between the current position and the target position. This could be done with Vector3.Lerp. Actually, the Unity Scripting Reference for Vector3.Lerp has as an example the exact script you are looking for :
I would use their example code like this :
var target : Transform;
var speed : float = 5.0;
function Update () {
transform.position = Vector3.Lerp( transform.position, target.position, speed * Time.deltaTime );
}
done =]
Think about what you want to make, then think about the most basic requirements, then work with that.
There is an alternative to your approach, just move the object towards the target at a constant speed, LookAt the target, then move forward :
var target : Transform;
var speed : float = 5.0;
function Update () {
transform.LookAt( target );
transform.position += transform.forward * speed * Time.deltaTime );
}
Hope this helps =]