Firing at the correct point
Blitz3D Forums/Blitz3D Programming/Firing at the correct point
| ||
Hello, I have a craft rotating in 3d space and I want it to fire from the correct point at the correct angle. What is the best way to achieve this? Would the following be a good (simple) way? Have the ship and have an extra vertex where the bullet should come from. Then when the ship is rotated the extra vertex is rotated aswell. Then I just 'read' where the extra vertex is and 'add' a bullet? I'm also concerned about reading the vertex before the UpdateWorld command is done; should I be? Any advice appreciated Marg |
| ||
I did something like this in my game. I have the ship fixed in the middle of the screen and I fire at the badguys passing by. Look at the tutorials: http://www.blitzbasic.co.nz/Community/posts.php?topic=35127 I used types to set up the bullets (Ross told me how) and to define angles and placement. I also used types to check for collision and then make the boom thig happen. Hope that helps. -Rook Zimbabwe |
| ||
Use the Tform... commands: use this to place your bullet five units infront of your ship: TFormPoint 0,0,5,ship,0 PositionEntity bullet,TFormedX(),TFormedY(),TFormedZ() And this to rotate your bullet: TFormVector 0,0,1,ship,0 AlignToVector bullet,TFormedX(),TFormedY(),TFormedZ(),3 Now move your bullet with the MoveEntity command each frame, where speed# is the speed of the bullet: MoveEntity bullet,0,0,speed# |
| ||
or you could parent a pivot to the ship, and position the bullet at the pivots position and rotate it to the ships angles: dummy=createpivot() parententity dummy, ship translateentity dummy,0,0,2 ... positionentity bullet, entityx(dummy,1), entityy(dummy,1), entityz(dummy,1) rotateentity bullet, entitypitch(ship), entityyaw(ship), entityroll(ship) and then, to move the bullet trough space, use moveentity bullet,0,0,speed# - as in Jeppes Example |