我如何使用Ursina实现敌人碰撞并改变Ursina的子弹方向?



我正在制作一款Ursina游戏,当我进入敌人碰撞时,它会出现这样的错误:

Traceback (most recent call last):
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinamain.py", line 126, in _update
__main__.update()
File "C:/Users/Minerva Panganiban/OneDrive/Desktop/Python/Ursinale.py", line 128, in update
destroy(bullet, enemy)
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinaursinastuff.py", line 48, in destroy
s = Sequence(
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinasequence.py", line 42, in __init__
self.generate()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinasequence.py", line 52, in generate
self.duration += arg.duration
TypeError: unsupported operand type(s) for +=: 'int' and 'Entity'
Traceback (most recent call last):
File "C:/Users/Minerva Panganiban/OneDrive/Desktop/Python/Ursinale.py", line 136, in <module>
app.run()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinamain.py", line 234, in run
super().run()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesdirectshowbaseShowBase.py", line 3325, in run
self.taskMgr.run()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesdirecttaskTask.py", line 546, in run
self.step()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesdirecttaskTask.py", line 500, in step
self.mgr.poll()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinamain.py", line 126, in _update
__main__.update()
File "C:/Users/Minerva Panganiban/OneDrive/Desktop/Python/Ursinale.py", line 128, in update
destroy(bullet, enemy)
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinaursinastuff.py", line 48, in destroy
s = Sequence(
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinasequence.py", line 42, in __init__
self.generate()
File "C:UsersMinerva PanganibanAppDataLocalProgramsPythonPython39libsite-packagesursinasequence.py", line 52, in generate
self.duration += arg.duration
TypeError: unsupported operand type(s) for +=: 'int' and 'Entity'

查看错误,我找不到问题所在。

这是我正在制作的游戏代码:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina()
class Ground(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'plane',
texture = "Cube",
scale = 500,
position = Vec3(0, 0, 0),
collider = 'plane')
class Cube(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'cube',
texture = "Sun",
scale = 50,
position = Vec3(250, 0, 250),
collider = 'box')
class Cube2(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'cube',
texture = "Sun",
scale = 50,
position = Vec3(-250, 0, -250),
collider = 'box')
class Cube3(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'cube',
texture = "Sun",
scale = 50,
position = Vec3(-250, 0, 250),
collider = 'box')
class Cube4(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'cube',
texture = "Sun",
scale = 50,
position = Vec3(250, 0, -250),
collider = 'box')
class Sky(Entity):
def __init__(self):
super().__init__(
parent = scene,
model = 'sphere',
texture = "Bla",
scale = 2050,
double_sided = True)
class Weapon(Entity):
def __init__(self):
super().__init__(
parent = camera.ui,
model = 'cube',
texture = "Untitled",
scale = 0.5,
rotation = Vec3(0, 0, 5),
position = Vec3(0, 0, 0))
def active(self):
self.rotation = Vec3(0, 45, 5)
self.position = Vec3(0, 0, 1)
def passive(self):
self.rotation = Vec3(0, 0, 5)
self.position = Vec3(0, 0, 0)
player = FirstPersonController(model='cube',
texture = "face",
scale=0.75,
collider = 'box',
speed = 2.255)
camera.z = -5
ground = Ground()
cube = Cube()
cube2 = Cube2()
cube3 = Cube3()
cube4 = Cube4()
sky = Sky()
weapon = Weapon()
window.title = 'Ursinale'
window.borderless = False
window.fullscreen = False
window.exit_button.visible = False
window.fps_counter_enabled = True
window.color = color.black
enemy = Entity(parent = scene,
model = 'cube',
texture = "ArcataPonte1",
position = Vec3(2000, 2000, 2000),
scale = 25,
collider = 'box')
enemy.add_script(SmoothFollow(target=player,
offset=[0,0,0],
speed = 0.255))
bullet = None
def input(key):
global bullet
if key == 'left mouse down':
bullet = Entity(parent=weapon, model='cube', scale=.1, color=color.black, collider='box')
bullet.world_parent = scene
bullet.animate_position(bullet.position+(bullet.forward*500), curve=curve.linear, duration=2)
destroy(bullet, delay=2)
def update():
global enemy
if bullet and bullet.intersects(enemy).hit:
hit_info = bullet.intersects(enemy)
print('enemy hit')
destroy(bullet, enemy)
enemy = None
if held_keys['left mouse']:
weapon.active()
else:
weapon.passive()
app.run()

是有任何错误,还是Ursina被bug了?另一个问题是你如何根据玩家面对的方向改变子弹的方向?

destroy(bullet, enemy)错误。第二个参数是延迟,应该是一个数字,而不是实体。

相关内容

  • 没有找到相关文章