2 回答
TA贡献1875条经验 获得超3个赞
你可以这样做Vector3.Lerp:
Vector3 startPosition;
Vector3 endPosition;
var speed = 10.0;
transform.position = Vector3.Lerp(startPosition, endPosition, speed * Time.deltaTime);
或使用 Vector3.MoveTowards
// 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);
TA贡献1796条经验 获得超7个赞
如果要滚动球,请AddForce()改用transform.position.
首先,将Rigidbody和添加Sphere Collider到您的球类游戏对象。
然后试试这段代码:
public Vector3 targetPoint;
public float forceAmount;
...
void Update()
{
Vector3 force = ((targetPoint - transform.position).normalized * forceAmount * Time.smoothDeltaTime);
GetComponent<Rigidbody>().AddForce(force);
}
另外,如果你想球在到达目标点后立即停止,你可以设置GetComponent<Rigidbody>().velocity为 0 时targetPoint - transform.position = 0
我希望它对你有帮助。
- 2 回答
- 0 关注
- 188 浏览
添加回答
举报