[英]SceneKit Child Physicsbody not moving when parent node is moving
我有2個簡單節點(2個球:一個在另一個上方,並且沒有接觸),每個節點都具有相同的物理特征。 下面的一個是父節點,上面的一個是子節點。
當我對父節點施加力時,兩個節點都在移動,但子節點的物理體卻不移動。 我已激活showphysicsshape選項,並且看到孩子的Physicalbody停留在原始位置。
我想念什么嗎?
Class Character3DClass: CharacterClass
{
var CharacterNode: SCNNode!
var CenterBody: SCNNode!
func InitChar()
{
InitBodyParentNode()
AddCenterBody()
}
func InitBodyParentNode()
{
CharacterNode.physicsBody = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(node: CharacterNode, options: [:]))
CharacterNode.physicsBody?.isAffectedByGravity = false
CharacterNode.physicsBody?.mass = 1
CharacterNode.physicsBody?.charge = 0
CharacterNode.physicsBody?.friction = 0
CharacterNode.physicsBody?.rollingFriction = 0
CharacterNode.physicsBody?.restitution = 0
CharacterNode.physicsBody?.damping = 0
CharacterNode.physicsBody?.angularDamping = 0
// Affectation des caractéristiques pour la gestion des collisions
CharacterNode.physicsBody?.categoryBitMask = eNodePhysics.Player.rawValue
CharacterNode.physicsBody?.contactTestBitMask = eNodePhysics.Player.rawValue | eNodePhysics.Ennemy.rawValue
CharacterNode.physicsBody?.collisionBitMask = eNodePhysics.TileBorder.rawValue
}
func AddCenterBody()
{
CenterBody = SCNNode(geometry: Level3D.Dot.geometry)
CenterBody.categoryBitMask = eNodePhysics.PlayerCenter.rawValue
CenterBody.position = SCNVector3.init(0, 3, 0)
CenterBody.scale = SCNVector3.init(0.4, 0.4, 0.4)
CenterBody.physicsBody = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: CenterBody.geometry!, options: nil))
CenterBody.physicsBody?.isAffectedByGravity = false
CenterBody.physicsBody?.mass = 1
CenterBody.physicsBody?.charge = 0
CenterBody.physicsBody?.friction = 0
CenterBody.physicsBody?.rollingFriction = 0
CenterBody.physicsBody?.restitution = 0
CenterBody.physicsBody?.damping = 0
CenterBody.physicsBody?.angularDamping = 0
CenterBody.physicsBody?.categoryBitMask = eNodePhysics.PlayerCenter.rawValue
CenterBody.physicsBody?.contactTestBitMask = eNodePhysics.PlayerCenter.rawValue
CenterBody.physicsBody?.collisionBitMask = eNodePhysics.NoValue.rawValue
CharacterNode.addChildNode(CenterBody)
}
}
您可以使用func resetTransform()
方法使物理主體與它的節點匹配,但是會降低性能: https : //developer.apple.com/documentation/scenekit/scnphysicsbody/1514782-resettransform
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.