Reputation: 440
In the example project of sceneKit
I am trying to make the camera look at the ship object which I have offset from the center. But for some reason I am unable to do it.
I use the following code to look at the ship. but it still gives as error:
Could not find an overload for init.
I am using swift to code.
cameraNode.constraints = SCNLookAtConstraint(ship)
pls help. Thanks.
Upvotes: 0
Views: 1786
Reputation: 2546
This kind of setup works for me, obviously you're better off not just unwrapping the node in case it doesn't exist, but it gives the general idea.
let targetNode = scene.rootNode.childNodeWithName("nodeName", recursively: false)
let constraint = SCNLookAtConstraint(target: targetNode!)
cameraNode?.constraints = [constraint]
Upvotes: 1
Reputation: 126177
I see the following in autocomplete, which looks promising:
This is the Swift form of the ObjC factory method +lookAtConstraintWithTarget:
.
In general, there are three easy ways to find out how an ObjC factory method (like +[NSFoo fooWithBar:]
) translates to a Swift initializer (like init(bar:)
, which you call with the syntax NSFoo(bar: heresABar)
):
Upvotes: 1
Reputation: 13462
you have to create a look-at constraint with +lookAtConstraintWithTarget:.
Also note that the constraints
property expects an array.
Upvotes: 0