问题描述
我有两个对象,我们称它们为 nearObject 和 farObject.一旦nearObject 与farObject 相距一定距离,我希望farObject 旋转以面向nearObject.这应该立即发生,它不需要随着时间慢慢旋转.
I have two objects, let's call them nearObject and farObject. Once nearObject gets within a certain distance from farObject, I want farObject to rotate to face nearObject. This should happen instantly, it does not need to slowly rotate over time.
1) 距离是任意的,所以我使用以下来获取距离信息.NearObject.position.distanceToSquared(farObject.position);
1) The distance is arbitrary, so I am using the following to get distance information.nearObject.position.distanceToSquared(farObject.position);
2) 现在我想让 farObject 垂直于两个对象之间的向量旋转.最简单的方法是什么?
2) Now I want farObject to rotate perpendicular to the vector between the two objects. What is the easiest way to do this?
推荐答案
farObject.lookAt( nearObject.position );
这篇关于将一个物体指向远处的物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!