I recently hacked out a little game with the distance calculation code snippet from the db tutorials in which you're a jet being chased by a robot who if he gets close enough starts to kill you etc.. I decided to finish it and made some health bars, sounds and, this is where the problem starts, gave the player an auto-aim macine gun. I works, but not very well. Sometimes the bullets damage him and sometimes they don't. Since I'm not on the same computer that I wrote it on, I can't enclude a good code snippet but I'll do my best.
If spacekey()=1
show object whatever
position object whatever, x,y,z (It's not that important)
bulletlife=12
gosub shoot_bullet
endif
shoot_bullet:
if bulletlife>0
dec bulletlife
endif
`aim at enemy
point object whatever,enemyx,enemyy,enemyz
move object whatever,5
`check if bullet is dead
if bulletlife=0
hide object whatever
return
Then the program would continue on to check if the enemy was hit, and lower the health bar, and so on. Please tell me if there's any better way to do this, my code's probably gonna be hard to read because I can't directly copy it, but I'm new at this, so give me a little slack.
If you come to a fork in the road, take it!
-Yogi Berra