英文:
How to switch physics body type in SceneKit
问题
我在游戏中有一个运动学刚体,当需要跳跃时,我将其切换为动态刚体,以便物理模拟可以处理重力的所有复杂性。我是通过替换节点的整个物理刚体来实现的。然而,这样做也会重置所有可以自定义的物理刚体属性。是否有一种方法可以更改节点的物理刚体而不创建新的物体?或者至少有一种方法可以“复制”所有值,比如恢复、角阻尼等。
我迄今为止尝试过的方法:
- 更改物理刚体的
type
属性,但文档说它应该是一个常量(尽管它是一个可获取-设置的属性???)。我不想违反文档,所以我不认为这是正确的方法。 - 尝试使用指针和反射来以某种方式复制这些值。我昨天开始阅读关于
Mirror
的内容,所以我不确定是否可以实现这样的功能,但我正在考虑它。 - 使用
copy()
函数,但是我仍然需要手动复制所有小的设置。
请告诉我是否有一种方法可以在保留其属性(如位掩码、物理设置等)的情况下切换物理刚体类型。
谢谢
英文:
I have a kinematic body in my game that I switch to a dynamic body when it needs to jump so the physics simulation can handle all the complexities of gravity. I do this by replacing the entire physics body of the node. However, doing this also resets all the customisation you can do to physics bodies. Is there any way to change the physics body of a node without creating a new one? Or at least a way that somehow “copies” all the values like restitution, angular dampening, etc.
What I’ve tried so far:
- Changing the
type
property on a physics body but the documentation says it’s supposed to be a constant (even though it’s a get-set property???). I don’t want to go against the documentation so I don’t think this should be the right way - Experimenting with pointers and reflections to copy the values somehow. I started reading about
Mirror
yesterday so I’m not sure if functionality like this even would be possible, but I am considering it. - Using the
copy()
function, however, I’d still have to manually copy all the small settings
Please let me know if there’s a way to switch the physics body type while preserving its properties such as bitmasks, physics settings, etc.
Thanks
答案1
得分: 1
SCNPhysicsBody
由其自己的 "构建" 几何形状组成,因此每当您想要更改它时,您需要重新创建它。但是,您可以例如预先定义所有所需的 physicsBodies
(动态、静态、运动学,包括所有属性如位掩码等)并将其分配给您需要的那个。
英文:
As a SCNPhysicsBody
consists of its own "constructed" geometry, you will need to recreate it each time you want to change it. But you could i.Ex. predefine all physicsBodies
you need (dynamic, static, kinematic, including all properties like bitmasks, etc...) in a set of variables or constants and then you assign the one you want at the moment you need it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论