本文介绍了Unity - 将对象移动到点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用下面的代码将球移动到确定的点.但是,球正在传送"到那里,我如何才能将球滚动到点?
I'm using the code below to move a Ball to determined point. But, the ball are "teleporting" to there, how can i roll the ball until the point ?
void Update(){
if (Input.GetMouseButtonDown(0) && EventSystem.current.currentSelectedGameObject != ButtonDiminuir && EventSystem.current.currentSelectedGameObject != ButtonAumentar &&
EventSystem.current.currentSelectedGameObject != BarraForca) {
transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, transform.position.y, -9.0424f), 2 * Time.deltaTime);
Anim.Play("Kick_Up");
}
}
推荐答案
你可以像这样使用 Vector3.Lerp
:
You can do it like this using Vector3.Lerp
:
Vector3 startPosition;
Vector3 endPosition;
var speed = 10.0;
transform.position = Vector3.Lerp(startPosition, endPosition, speed * Time.deltaTime);
// The step size is equal to speed times frame time.
float step = speed * Time.deltaTime;
// Move our position a step closer to the target.
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
这篇关于Unity - 将对象移动到点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!