- Home /
Question by
iamthecoolguy11 · Nov 07, 2013 at 12:39 AM ·
c#movementtransformtranslate
how do i slowly translate a object to a other objects position
I'm making a character that you click and he walks the next spot you click. I already got him to move where I click but he moves there in about 2 frames and I can't slow it down.
heres what i mean
public GameObject ObjectToMoveTo;
void Update()
{
//transform the player to ObjectToMoveTo at a controllable
//speed with out useing look at
}
Comment
Best Answer
Answer by Crazydadz · Nov 07, 2013 at 01:41 AM
Vector3.MoveTowards() is what you are looking for
public class Example : MonoBehaviour {
public Transform target;
public float speed;
void Update() {
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}
Thanks man i was trying to get this to work forever
good one. really need that . but why you did not multiply speed with target.position?
Answer by JuanseCoello · Nov 07, 2013 at 01:36 AM
I think it is a very useful question that deserves to be answered for everybody to learn.
It's been answered, very clearly, many many times before.