allowRotation in SceneKit?

眉间皱痕 提交于 2019-12-11 13:13:06

问题


How can I disallow rotation of a node in SceneKit?

For ex., I want a model (cone) to be dynamic, jumping and flying, but always vertically oriented?

I tried fix it like in apple's vehicle demo, it is bad solution. Also I tried below code, but model just slowly and glitchy falls down

- (void)renderer:(id<SCNSceneRenderer>)aRenderer didSimulatePhysicsAtTime:(NSTimeInterval)time{
    _node.rotation = SCNVector4Make(0, 0, 0, 0);
    //[_node.physicsBody resetTransform]; // - tried this too
}

...and finally I did not find any "allowRotation=NO" in scenekit manuals.


回答1:


Instead of a Boolean allowsRotation flag like in SpriteKit, SceneKit lets you choose which directions a body is allowed to rotate in and by how much. See the angularVelocityFactor property.

This is probably a better idea than toggling the mass between different values — that approach looks like it could be unintended behavior, so you might not want to rely on it.




回答2:


If you want to mix physics simulation and manual transforms, make sure to use a "kinematicBody" and not a "dynamicBody".




回答3:


Ahaha, I found some bug solving this problem (but this is a bug, so it is weird)

  1. create node
  2. set mass=1
  3. add node to scene
  4. set mass=0 - this makes it static and unmovable, but...
  5. set mass=1 - this makes it dynamic, jumping and falling but with fixed rotation!

iOS 8.0.2 iPad mini




回答4:


Simple solution:

node.physicsBody?.allowsRotation = false



来源:https://stackoverflow.com/questions/26261554/allowrotation-in-scenekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!