I'm trying to make a horror type game in Ursina as a small project but I can't figure out how to position the point light. I want the point light to be pointing forward a bit and be at the players position.
This is the full code at the moment:
from ursina import *
from random import uniform
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import lit_with_shadows_shader
app = Ursina()
player = FirstPersonController(model='cube', color=color.orange, origin_y=-.5, speed=8, position = (-52, 0, 57))
player.collider = BoxCollider(player, Vec3(0,1,0))
player.visible = False
ammo = 10
playerHealth = 100
editor_camera = EditorCamera(enabled=False, ignore_paused=True)
ammoCounter = Text(text= ammo + ammo, position = (-0.4,-0.4), color = color.black)
ttt=PointLight(position= (-52, 0, 57), parent=camera.ui, color = color.rgba(100, 2, 100, 0), rotation = (0, 184, 0), shadows = True)
def update(): ##ammo counter ##
ammoCounter.text = ammo
def pause_input(key): ##editor camera thing##
if key == 'tab': # press tab to toggle edit/play mode
editor_camera.position = player.position
editor_camera.rotation = (90,180,0)
editor_camera.y = 50
editor_camera.enabled = not editor_camera.enabled
player.visible =True
player.visible_self = editor_camera.enabled
player.cursor.enabled = not editor_camera.enabled
gun.enabled = not editor_camera.enabled
mouse.locked = not editor_camera.enabled
application.paused = editor_camera.enabled
pause_handler = Entity(ignore_paused=True, input=pause_input)
def input(key): ## gunshot, gun, player shift, and ammo crates destroys
global ammo
if key == "2":
ttt.color = color.black
if key == "1":
ttt.color = color.white
## destroy ammo crates##
if key == 'e':
if mouse.hovered_entity == ammo1:
if distance(player, ammo1) <= 5:
try:
ammo += 10
except:
print('ammo issue')
try:
destroy(ammo1)
except:
print("ammo box issue")
if mouse.hovered_entity == ammo2:
if distance(player, ammo2) <= 5:
try:
ammo += 10
except:
print('ammo issue')
try:
destroy(ammo2)
except:
print("ammo box issue")
if mouse.hovered_entity == ammo3:
if distance(player, ammo3) <= 5:
try:
ammo += 10
except:
print('ammo issue')
try:
destroy(ammo3)
except:
print("ammo box issue")
if mouse.hovered_entity == ammo4:
if distance(player, ammo4) <= 5:
try:
ammo += 10
except:
print('ammo issue')
try:
destroy(ammo4)
except:
print("ammo box issue")
if key == 'k':
print (player.position)
print (player.rotation)
print (ammo)
print (ttt.position)
if key=="left mouse down" and ammo > 0:
ammo -= 1
if mouse.hovered_entity and hasattr(mouse.hovered_entity, 'hp'):
mouse.hovered_entity.hp -= 10
mouse.hovered_entity.blink(color.black)
print (ammo)
Audio("gunshot")
if gun.position == (0.45,-0.2,0):
Animation("spark", parent=camera.ui, fps=5, scale=.15, position=(0.28, -0.01), loop=False)
print (ammo)
if gun.position == (0,-0.15,0):
Animation("spark", parent=camera.ui, fps=5, scale=.15, position=(-0.005,0.08,0), loop=False)
print (ammo)
if held_keys["q"]:
gun.position = (0,-0.15,0)
gun.rotation = (0,0,0)
Cursor = False
player.speed = 1
if held_keys["shift"]:
player.speed = 100
else:
gun.position = (0.45,-0.2,0)
gun.rotation = (5,30,0)
player.speed = 250 * time.dt
if held_keys["shift"]:
player.speed = 400 * time.dt
class AmmoR(Entity): ## ammo refill class#
def __init__(self, **kwargs):
super().__init__(model='cube', texture = 'ammobox', scale = 1, origin_y=-0.5, collider = "mesh", **kwargs)
## amount of amo refill boxes##
ammo1 = AmmoR()
ammo2 = AmmoR()
ammo3 = AmmoR()
ammo4 = AmmoR()
ammo1.position = (-9,2,53)
ammo2.position = (50,1,21)
ammo3.position = (-17,0,31)
ammo4.position = (15,0,8)
class Enemy(Entity): ##enemy class#
def __init__(self, **kwargs):
super().__init__(model='cube', scale_y=4, origin_y=-0.5, color=color.light_gray, collider='box', texture = "monster", **kwargs)
self.health_bar = Entity(parent=self, y=1.2, model='cube', color=color.red, world_scale=(1.5,.1,.1))
self.max_hp = 100
self.hp = self.max_hp
def update(self):
global playerHealth
dist = distance_xz(player.position, self.position)
if dist > 40:
self.health_bar.visible = False
return
self.health_bar.alpha = max(0, self.health_bar.alpha - time.dt)
self.look_at_2d(player.position, 'y')
hit_info = raycast(self.world_position + Vec3(0,1,0), self.forward, 30, ignore=(self,))
if hit_info.entity == player:
if dist > 1:
self.position += self.forward * time.dt * 5
if player.intersects(self).hit:
print(playerHealth)
playerHealth -= 0.3
@property
def hp(self):
return self._hp
@hp.setter
def hp(self, value):
self._hp = value
if value <= 0:
destroy(self)
return
self.health_bar.world_scale_x = self.hp / self.max_hp * 1.5
self.health_bar.alpha = 1
## ENEMYS FIRST LEVEL
enemie1 = Enemy()
enemie2 = Enemy()
enemie3 = Enemy()
enemie4 = Enemy()
enemie5 = Enemy()
enemie6 = Enemy()
enemie7 = Enemy()
enemie8 = Enemy()
enemie9 = Enemy()
enemie10 = Enemy()
enemie11 = Enemy()
enemie1.position = (10,0,-2)
enemie2.position = (51.9096, 0, -57.6378)
enemie3.position = (53.7879, 0, -57.4827)
enemie4.position = (53.5366, 0, -39.0536)
enemie5.position = (50,0,-2)
enemie6.position = (50,0,-5)
enemie7.position = (22,0,-20)
enemie8.position = (55,0,-4)
enemie9.position = (15,0,-2)
Sky(color = color.black)
maze=Entity(model="maze", scale=10, texture="BK", color= color.gold ,collider="mesh")
gun=Entity(model="colt", parent=camera.ui, scale=0.07, texture='Maybe', position=(0.45,-0.2,0), rotation=(5,30,0))
app.run()
I just need to figure out on:
ttt=PointLight(position= (-52, 0, 57), parent=camera.ui, color = color.rgba(100, 2, 100, 0), rotation = (0, 184, 0), shadows = True)
and see if I can add a def update() function to make it go to the player position. The only thing is that when I change the position of the light I see no change in the effect.
I tried to move the light to another position but it s开发者_运维百科tayed the same. I am also trying to figure out how to change the brightness of the light.
精彩评论