Carlos C Carlos C - 2 months ago 23
iOS Question

How do I add a 2D view inside a 3D SCNNode in Scene Kit

I'm trying to add a type of "notification" above a 3D view that follows it and if the camera rotates or the SCNNode rotates that view always stay looking front, it's to "expensive" to do calculations and make a flat 3D and rotate it every time some of the parents rotates, or the camera, and I don't want to add an UIView over everything that is following the 3D xyz because I want it to interact with the 3D worls depth-sorting.

Here is an example of what I want to achieve:


It's a view that doesn't rotate with it's parents, how do I achieve it?

Thank you in advance!


I found a way of doing it, it's really simple as this:

SCNLookAtConstraint *constraint = [SCNLookAtConstraint lookAtConstraintWithTarget:cameraNode];
constraint.gimbalLockEnabled = YES;
nodeA.constraints = @[constraint];

This will make the nodeA always look at the camera and I set the gimbalLockEnabled = YES so it doesn't rotate weirdly.

Hope it helps someone out there, it saved my game :-)