Orient objects in same direction across devices

泪湿孤枕 提交于 2019-12-12 05:37:47

问题


I am making a first-person, multiplayer game using Three.js where players' opponents are represented on their screens as airplanes. I need to be able to orient the airplane on the screen of person B in the same direction as the camera of person A so that when person A moves forward, the airplane on the other person's screen moves forward AND faces forward, rather than drifting forward while facing backwards or sideways. I need transmit the orientation information as a JSON object. I tried transmitting the rotation property of the camera and setting the rotation property of the airplane based on that at the other end, but for some reason the airplane does all sorts of strange twists and flips and doesn't face the direction it should. What is the best way to set the orientation of an Object3D so that it faces same direction as the camera on another device?


回答1:


Camera and Object3D have a method named lookAt that rotates them to face the given direction. WARN: you should calculate the direction, it means:

(position you want to look at - position of your object).normalize();



来源:https://stackoverflow.com/questions/39379671/orient-objects-in-same-direction-across-devices

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