I am currently using Ursina Game Engine and am trying to make a basic FPS game. In the game, there is obviously a gun and a bullet.
The system I have for shooting the gun isn't working. First, it isn't moving forward the way I want it, and second, it isn't able to detect collision sufficiently.
I am wondering how I can make the gun shoot a bullet forward properly, and also how I can make it tell me when it hits something.
Here is the code I am using:
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()
I have tried using the raycast method in Ursina but that did not work.