我想製作一個浮球。在SceneKit中受重力影響?
在spritekit中,我做了physicsbody.affectedbygravity = NO;
但是我在做什麼scenekit?
我試圖將質量設置爲零,但動態變爲靜態:它不會因重力或碰撞而移動。我的代碼是
// add ball
SCNNode *ball = [SCNNode node];
ball.geometry = [SCNSphere sphereWithRadius:5];
ball.geometry.firstMaterial.locksAmbientWithDiffuse = YES;
ball.geometry.firstMaterial.diffuse.contents = @"ball.jpg";
ball.geometry.firstMaterial.diffuse.contentsTransform = SCNMatrix4MakeScale(2, 1, 1);
ball.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeMirror;
ball.physicsBody = [SCNPhysicsBody dynamicBody];
ball.physicsBody.restitution = 0.9;
//ball.physicsBody.mass=0; //here makes a ball statical and not moving
ball.physicsBody.allowsResting = YES;
[[scene rootNode] addChildNode:ball];
UPD這不是也有幫助 - 球緩慢下降。
- (void)renderer:(id<SCNSceneRenderer>)aRenderer didSimulatePhysicsAtTime:(NSTimeInterval)time{
[ball.physicsBody applyForce:SCNVector3Make(0, 9.8, 0) atPosition:SCNVector3Make(0,0,0) impulse:NO]; //this
ball.physicsBody.velocity=SCNVector3Make(0,0,0); //or this
}
我看到了,但Apple的手冊中沒有提到有關位掩碼的內容 - 請參閱https://developer.apple.com/library/prerelease/iOS/documentation/SceneKit/Reference/SCNPhysicsField_Class/index.html#//apple_ref/occ/ clm/SCNPhysicsField/linearGravityField -----所以,你的意思是我必須將相同的位掩碼設置爲「引力」模型和字段的節點? – djdance 2014-10-09 08:32:45
所以,Scenekit字段在這裏:https://developer.apple.com/library/ios/documentation/SceneKit/Reference/SCNPhysicsField_Class/index.html#//apple_ref/occ/instp/SCNPhysicsField/categoryBitMask – djdance 2014-11-05 16:49:26