my basic code is pretty much this on that tutorial: https://code.tutsplus.com/tutorials/an-introduction-to-scenekit-fundamentals--cms-23847
I want to make a sunrise behaviour. Something like the lightNode begins on the same height as the constrained cubeNode and move it up so that the shadow shall become smaller over time. Therefore I tried to move the nodes via SCNAction.move(to...).
Action on lightNode -> nothing happens
Action on the constrained cubeNode -> shadow starts to flicker, but no changing
I tried around with the shadowModes. I think I misunderstood this. No useful results came up.
Has anyone an idea if scenekit supports something like dynamicly changing shadows?
I found a way to make it. My major mistakes were:
Somehow it does not work to access the lightNode (it just has no effect, when actions for a
lightNode
are called)I tried to go via
SCNAction.move(to...)
. The answer is to use a rotation instead of a longitudinal movement.The answer was accessing the constraint Node (instead of the lightNode). In this code the cubeNode is replaced with an invisible
centerPoint
(as the constraint node where thelightNode
has to look at). AboxNode
has been added for making a canvas for the shadow. ThelightNode
has to be added to thecenterPoint
, NOT to the scene.There is the modified
viewDidLoad
-method. If you want to check this out, open Xcode, start a new project as SceneKit Game and replace theviewDidLoad
with the following code.There is also a color change of the light is considered. With a CABasicAnimation it is possible to change the
light.color
-property over time. It is not like a perfect sunrise with all color steps, but there is also a way to chain those animations to make it more complex. (For this search for "wenderlich how to create a complex loading animation".But I did not find a way to change the shadow color. It could be a nice effect to have white shadows on nighttime and black shadows on daytime.
light.shadowColor
did not help yet. If someone has an idea it is very appreciated.