Scenekit 相对于相机移动对象

发布于 2025-01-13 10:10:55 字数 184 浏览 1 评论 0原文

我已经在 Scenekit/ARKit 中放置了一个节点,

现在我想借助按钮将节点/对象左右移动。问题是当我移动相机/设备并按下右侧按钮时,节点沿首次启动的轴方向移动,而不是相对于相机向右移动。我怎样才能实现这个目标?

点击右键时的当前代码

position.x += 0.2

I've placed a node in Scenekit/ARKit

Now I want to move node/object to right and left with help of buttons. Issue is when I moves my camera/device and press right button, node moves in direction of axis it was first initiated, Not moves right with respect to camera. How can I achieve this?

current code on tapping right button

position.x += 0.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2025-01-20 10:10:55

这是解决方案

guard let front = sceneView.pointOfView?.simdWorldFront else {return}
let horazontalRight = cross(front, simd_float3(0,1,0))
    
// for moving right
node.position +=  SCNVector3(horazontalRight *  0.01)

Here is the solution

guard let front = sceneView.pointOfView?.simdWorldFront else {return}
let horazontalRight = cross(front, simd_float3(0,1,0))
    
// for moving right
node.position +=  SCNVector3(horazontalRight *  0.01)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文