- Home /
Translate issue with Vector3.MoveTowards
I have a problem with the translation, MoveTowards work normally with transform but When I try to use it through translate I've got many errors like following error:
transform.position assign attempt for 'SecondCpu' is not valid. Input position is { Infinity, -4461021470593428500000.000000, -4463786117814680600000.000000 }.
UnityEngine.Transform:Translate(Single, Single, Single)
My Code:
var MoveDir : Vector3;
MoveDir = Vector3.MoveTowards(mainObject.position, AIObject[0].position, avgSpeed);
mainObject.Translate(MoveDir * Time.deltaTime);
Answer by fafase · May 01, 2012 at 05:25 PM
var MoveDir : Vector3;
MoveDir = Vector3.MoveTowards(mainObject.position, AIObject[0].position, avgSpeed);
transform.Translate(MoveDir * Time.deltaTime);
OK it works this way but I don't get what you are trying to do. Both MoveTowards and Translate have a similar effect.
Also when doing this, the object keeps on going so I guess you cannot really do anything like this.
This is the code I used:
var MoveDir : Vector3;
var target: Transform;
var speed=0.001f;
function Update(){
MoveDir = Vector3.MoveTowards(transform.position, target.position, speed);
Debug.Log(MoveDir);
transform.Translate(MoveDir * Time.deltaTime);
}
And all it does is going towards the target, passes it and keeps on going and going faster and faster despite the 0,001.
Your answer
Follow this Question
Related Questions
Different between transform.Translate() and Vector3.MoveTowards? 1 Answer
Setting target position in Vector3.MoveTowards 2 Answers
Camera moveTowards stuttering in place? 1 Answer
Move child objects in the opposite direction of parent object 0 Answers
How the player can translate 1 "unit" and not smouthly. 2 Answers