我目前正在使用Ursina游戏引擎,并试图制作一个基本的FPS游戏。在游戏中,显然有一把枪和一颗子弹
我的射击系统坏了。首先,它没有按照我想要的方式前进,其次,它无法充分检测碰撞
我想知道如何让枪正确地向前射出一颗子弹,以及如何让它在击中某物时告诉我
以下是我正在使用的代码:
def shoot():
print(globalvar.currentmag, globalvar.total_ammo)
if globalvar.currentmag > 0:
bullet = Entity(parent=weapon, model='cube', scale=0.1, color=color.brown, collision = True, collider = 'box')
gunshot_sfx = Audio('Realistic Gunshot Sound Effect.mp3')
gunshot_sfx.play()
bullet.world_parent = scene
bullet.y = 2
for i in range(3000):
bullet.position=bullet.position+bullet.right*0.01
globalvar.currentmag -= 1
hit_info = bullet.intersects()
print(hit_info)
if hit_info.hit:
print("bullet hit")
destroy(bullet, delay=0)
destroy(bullet, delay=1)
else:
reload()
我曾尝试在Ursina中使用光线投射方法,但没有成功
不要在创建项目符号后立即更新其位置。相反,使用它的
animate_position()
方法让Ursina更新它。然后可以在全局update()
函数中检查冲突。确保所有涉及的实体都有一个碰撞器,并且它们可以在全球范围内访问我根据
FirstPersonController
类中的演示代码改编了这个示例。我不确定在调用bullet.intersects()
时是否有不指定其他实体的方法。我认为它应该可以工作,因为hit_info
对象有各种属性,其中entities
但是我自己无法让它工作相关问题 更多 >
编程相关推荐