3

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:

Example

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

Thank you in advance!

c4b4d4
  • 964
  • 12
  • 32
  • 1
    so basically you rotate the banner in the opposite direction of its parent (always facing camera), done. Why should that be too expensive? – CodeSmile Jan 04 '15 at 10:47
  • @LearnCocos2D It's a game an it involves tons of nodes, there will be lots of fors going on just to rotate the banners plus you're free of rotating the camera, so there will be lots of calculations. – c4b4d4 Jan 04 '15 at 16:51
  • you can use shader modifiers to do that, and if you work in view space (the coordinate system of the camera) everything becomes simple. You can look for "billboard shader" on the web. – mnuages Jan 04 '15 at 17:06
  • it's a game, there *will* be lots of calculations. Don't not do something because you are afraid it might be slow. Make it work and when you find a performance problem, then you analyse and optimize. – CodeSmile Jan 04 '15 at 17:06
  • plus, I betbthat if you have tons of nodes, chances are that the rotation calculations will hardly contribute at all, most games are entirely gpu limited ie it takes a lot more time to draw a 3d model than some measly offset calculations. – CodeSmile Jan 04 '15 at 17:08
  • I just found this: `nodeA.constraints = @[[SCNLookAtConstraint lookAtConstraintWithTarget:nodeB]];`it makes something always look at some other thing, this is perfectly what I need, I'll test it out and post it as an answer if I succeed. – c4b4d4 Jan 04 '15 at 17:58

1 Answers1

3

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 :-)

c4b4d4
  • 964
  • 12
  • 32