Reputation: 29
I just started learning the Ursina game engine and I was wondering if there was any way to add lighting against entities. I'm trying to make an FPS game and it seems I can't find anything on the topic of lighting! It surprising and frustrating so, please help me out. :)
Upvotes: 1
Views: 750
Reputation: 227
You will need to add lights (directional
, point
, spot
or ambient
). And then use a shader like lit_with_shadows_shader
. The code will be:
from ursina import *
from ursina.shaders import lit_with_shadows_shader
class Lights:
def __init__(self):
self.pivot = Entity()
self.direc_light = DirectionalLight(parent=self.pivot, y=2, z=3, shadows=True, rotation=(45, -45, 45))
self.amb_light = AmbientLight(parent=self.pivot, color = color.rgba(100, 100, 100, 0.1))
app = Ursina()
# Set shader to all entities
Entity.default_shader = lit_with_shadows_shader
# Lights
Lights()
pivot = Lights().pivot
direc_light = Lights().direc_light
amb_light = Lights().amb_light
# Create entity
cube1 = Entity(model='plane', color = color.blue, position = (0,0,0), scale=(10,10,0), collider='box')
cube2 = Entity(model='cube', color = color.red, position = (3,3,0), collider='box')
app.run()
Upvotes: 0
Reputation: 661
Easy way:
for x in range(some_intager):
for z in range(some_other_intager):
Entity(model='cube', x=x, z=z, shader=lit_with_shadows_shader)
DirectionalLight(parent=pivot, y=2, z=3, shadows=True, rotation=(45, -45, 45))
Upvotes: 1
Reputation: 109
The best I can offer is that you make a nested for loop above the map and place objects.
Here is the code:
for x in range(some_intager):
for z in range(some_other_intager):
Entity(model='cube', x=x, z=z, shader=lit_with_shadows_shader)
Upvotes: 0