gpt4 book ai didi

ios - 当父节点移动时,SceneKit 子物理主体不移动

转载 作者:行者123 更新时间:2023-11-30 11:37:52 25 4
gpt4 key购买 nike

我有 2 个简单节点(2 个球:一个在另一个之上且不接触),每个节点都有一个具有相同特性的物理体。下面的是父节点,上面的是子节点。

当我向父节点施加力时,两个节点都在移动,但子节点的物理主体不移动。我激活了 showphysicalshape 选项,我看到 child 的物理体留在原来的位置。

我错过了什么吗?

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

关于ios - 当父节点移动时,SceneKit 子物理主体不移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49542611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com