- Home /
How to use "move to target"?
Alright so I want a ball to move to a cube, I remember watching a tutorial where they used "moveto (target)" or something like that?
Answer by adrenak · Dec 29, 2011 at 08:01 PM
I haven't come across the moveto target and the scripting Unity manual also doesnt show up anything like that, but theres a different way you can do it.
Heres something in JS:
var target : Transform;
var speed : int;
function Update(){
transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
}
just save this and add it to the ball. Once the script is compiled, drag the cube from the heirarchy to the 'target' variable.
Answer by The_Magical_Kiwi · Jul 11, 2013 at 11:01 AM
I know this is super old, but I came across it when I was looking for the same thing this guys was and the answer turned out to be.
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.MoveTowards.html
Your answer
Follow this Question
Related Questions
A* pathfinder - next target 1 Answer
How to use js to add an camera target texture to an objects's renderer.materials 2 Answers
Look at +1z of target and move to -1z of target? Almost there! 2 Answers
Else Statement Not Working 1 Answer
Changing camera target of CarSmoothFollow ( Js to c#) 0 Answers