Moving an object with vector3.MoveTowards

让人想犯罪 __ 提交于 2019-12-02 03:21:27

Vector3.MoveTowards takes the current position, the target position, and the step, but it seems like your first argument here is origin of the move, rather than current position. Normally you'd do this something like this, in your Update():

transform.localPosition = Vector3.MoveTowards (transform.localPosition, PositionB, Time.deltaTime * speed);

with the current position as the first argument.

Here is how to use MoveTowards:

void Update()
{
    float step = speed * Time.deltaTime;
    transform.position = Vector3.MoveTowards(transform.position, PositionB, step);
}

LearnMore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!