我想在一个场景中添加多个对象,但是我似乎并没有为如何使用touches: Set<UITouch>
是否有一种更有效的方法来处理每次特定屏幕触摸后一次添加对象请求?
答案 0 :(得分:0)
添加一个手势识别器,获取(点击的)currentLocation,然后将2D屏幕坐标取消投影到3D世界空间。 scenePoint包含您需要的向量。如果您向下看-Z轴,而Y向上,这将起作用。
var currentLocation = CGPoint.zero
@objc func handleTap(recognizer: UITapGestureRecognizer)
{
currentLocation = recognizer.location(in: gameScene)
let projectedPoint = gameScene.projectPoint(SCNVector3(0, 0, 0))
let scenePoint = gameScene.unprojectPoint(SCNVector3(currentLocation.x, currentLocation.y, CGFloat(projectedPoint.z)))
{
placeObject(vPosition: scenePoint)
}
}