I have a text node. I am telling the node to always look at the camera node like so:
let lookAt = SCNLookAtConstraint(target: cameraNode)
textNode.constraints = [lookAt]
Before I apply that constraint the text looks like this: (see image)
If I apply that constraint, the node look flipped like in the image (see image). So, the text does always keep that orientation and correctly look at the camera node, so the constraint is working.
I am trying to understand how the node "looks" at the target node though. I would obviously want the text to simply stay like shown in the first image as the camera moves around.
I tried to apply a rotation to the text to correct the behavior I get when applying the constraint but didn't work.
So, how can I get the text to have look at another node but not be flipped like in the second image?
The documentation for SCNLookAtConstraint
notes:
When SceneKit evaluates a look-at constraint, it updates the constrained node's
transform
property so that the node's negative z-axis points toward the constraint's target node.
But SCNText
geometry is created facing forward along its positive z-axis, so your constraint system needs to account for that in some way. I advise using SCNBillboardConstraint
, which is designed for this kind of case. Its documentation says:
An
SCNBillboardConstraint
object automatically adjusts a node's orientation so that its local z-axis always points toward thepointOfView
node currently being used to render the scene.
With this, you shouldn't need to reparent the node.
The "SCNBillboardConstraint object automatically adjusts a node's orientation so that its local z-axis always points toward the pointOfView node currently being used to render the scene."
textNode.constraints = [SCNBillboardConstraint()]
You can also modify lookAt constraint by specifying the axis through which it will "look" via the localFront property:
let lookAtConstraint = SCNLookAtConstraint(target: distantNode)
lookAtConstraint.localFront = SCNVector3Make(0, 1, 0)
node.constraints = [lookAtConstraint]
The above code will orient the node to distantNode via it's Y-axis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With