简体   繁体   English

两个动态SCNNode不冲突(Scenekit)

[英]Two Dynamic SCNNodes Not Colliding (Scenekit)

I am currently in the process of making a Scenekit game in ARKit. 我目前正在使用ARKit制作Scenekit游戏。

I have two dynamic SCNNodes, and when they make contact with each other, they pass through one another. 我有两个动态SCNNode,当它们相互联系时,它们会彼此通过。

I have set up each node's physics body's collisionBitMask to include one another, like so: 我已经将每个节点的物理实体的冲撞位掩码设置为彼此包含,如下所示:

ballNode.physicsBody?.collisionBitMask = BodyType.floor.rawValue |  BodyType.opponent.rawValue

I have also set up the physics body of each node to be dynamic, so that the node is affected by forces and collisions. 我还将每个节点的物理主体设置为动态的,以便该节点受力和碰撞的影响。

When I call physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) it does correctly register that there is a collision between the two nodes, however the nodes continue to pass through one another. 当我调用physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact)它确实正确地注册了两个节点之间存在冲突,但是这些节点继续彼此通过。

When I make one of the nodes kinematic, instead of dynamic, it correctly blocks the other node, and they do not pass through one another. 当我使一个节点运动时,它不是动态的,而是正确地阻塞了另一个节点,并且它们彼此之间不会通过。 But when it is kinematic, it does not respond to the force I apply to it, so I want to keep it dynamic. 但是,当它是运动学时,它不会响应我施加给它的力,因此我想使其保持动态。

Is it possible to have two dynamic nodes to collide with one another without passing through? 是否可以有两个动态节点相互碰撞而不经过?

I think the "physicsShape" is missing, so declared as "nil" 我认为缺少“ physicsShape”,因此声明为“ nil”

geometryNode.physicsBody = SCNPhysicsBody(type: .Dynamic, shape: nil)

Instead: 代替:

let pShape = SCNPhysicsShape(geometry: SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0.0), options: [:])
boxNode.physicsBody = SCNPhysicsBody(type: .Dynamic, shape: pShape)

I hope the helps, please post the code. 希望对您有所帮助,请发布代码。

An alternative for the shape creation is init(node:options:) 形状创建的替代方法是init(node:options :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM