Sam Sam - 10 months ago 64
Objective-C Question

Stop Camera from rotating around a rotating parent

I have a rolling marble and would like my camera to follow it. My problem is that my camera is also rotating around my object as it is rotating.

Here's my code.

-(void) setupCameraOnMarble:(SCNNode*)marble
{
[cameraNode removeFromParentNode];

[marble addChildNode:cameraNode];

SCNLookAtConstraint *marbleStare = [SCNLookAtConstraint lookAtConstraintWithTarget:marble];

marbleStare.gimbalLockEnabled = YES;

cameraNode.constraints = @[marbleStare];
}


I'm thinking that a transform constraint should work but I don't understand how it works.

Answer Source

Are you sure you need to make cameraNode a child of marble?

Because according to SKNode docs: when a node’s coordinate system is scaled or rotated, this transformation is applied both to the node’s own content and to that of its descendants see SKNode

So i assume you need to un-child camera from marble. And to achive that followint the object behavior from camera, you may update camera coordinates somewhere in the code, that moves the marble

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download