I am programming a 2D/3D game.
I use as floor some plane egg, with ground texture, and for character, a plane egg, too, but at the vertical of the ground, with a 2d character texture.
I wish to have an ambient light to darkness the game, and have over the character a light to show the decor around the player, in a circle radius.
It is light a lamp over the character, moving with it.
I don’t know how to do that.
Can you help, please?
Presuming that you already know ho to create lights and add them to your scene, you should be able to simple reparent the light’s NodePath to your character; it should thereafter follow said character around.
If you don’t yet know how to create lights, I recommend reading this section of the manual, which should instruct you on such.
One note, however: you mention wanting a circular extent for the light, which may call for turning on the automatic shader system; you can do so, I believe, by placing “render.setShaderAuto()” at some point in the initialisation sections of your code.
yeah, I already read this part of the manual, and it is ok for the ambient light.
alight = AmbientLight('alight')
alight.setColor(VBase4(0.1, 0.1, 0.1, 1))
alnp = render.attachNewNode(alight)
Concerning the “lamp” I tried something like that :
slight = Spotlight('slight')
slight.setColor(VBase4(1, 1, 1, 1))
lens = PerspectiveLens()
self.slnp = characterNode.attachNewNode(slight)
self.slnp.setPos(0, 20, 0)
For all decor, characters, & monsters, it is ok, the lamps lights them. These one are vertical tiles.
But the horizontal tiles (ground) are not light on, they are always in darkness. And I don’t understand why…
Where did you get the ground-plane egg file? I suspect, given your description, that the plane’s normals face downwards, causing it to be considered to be facing away from the light, and thus being unlit.
If the plane is two-sided, try rotating it through 180 degrees (note that if the plane is not two-sided it will probably disappear when rotated through 180 degrees); if not, and you are in a position to edit the plane’s model in a 3D editor, try flipping the normal in that editor. If none of that helps, perhaps try scaling it by -1 in your “up” direction.
Placing the light with another position, and it is good
self.slnp.setPos(0, 20, -10)
It seems that the light was in horizontal, and did’nt light the ground. In this position, the light is in diagonal, and lights decor and ground.
Thanks for your time