Setting Azimuth and Elevation of light source in Panda3D

I want to set azimuth and elevation of my light source so that it can act like the sun for illumination of lunar surface terrain, please tell me how should I do that.

Create a DirectionalLight with direction (0, -1, 0), place it in the scene graph, and use nodePath.setH() to control its azimuth and setP() to control its elevation in degrees.

If you instead have a Spotlight or PointLight, then you need to attach it to a dummy node that is centered on the camera, and instead call setH and setP on the dummy node.

Thankyou.

“If you instead have a Spotlight or PointLight, then you need to attach it to a dummy node that is centered on the camera, and instead call setH and setP on the dummy node.”

Please help me on syntax for the statement above.
How to create a dummy node that is centered on camera?

# Create the dummy
dummy = render.attachNewNode("lightpivot")

# Attach the point light to the dummy, but place it very far northwards (whichever direction north is in your game)
lightNp = dummy.attachNewNode(pointlight)
lightNp.setPos(0, 1000, 0)

# Set azimuth and elevation
dummy.setHpr(azimuth_in_degrees, elevation_in_degrees, 0)

It might be that you’ll have to flip the sign on the elevation, I always forget which way is which.

Ok, I will try this code. Thankyou :slight_smile: