Welcome, Guest. Please Login or Register.  • Help
SMF Underground
+ SHMUP-DEV » SHMUP DEV FORUMS » Assistance
|-+ How do you shoot Bullets???

Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read January 09, 2006, 11:31:56 PM #0
RedKnight

How do you shoot Bullets???

Grin
Is not that I don't know how to shoot Bullets.
Is just I'm interested on how people making bullets shoot from their ship.  Grin
I just wanted to compare codes with other coders on how they do it.
and Also I wanted to pimp up my post count  Tongue Grin for the 100 buck



well here I go!


In all of My Bullet class I use this algorithm

Code:

void                Homing( VECTOR3D &Pose, VECTOR3D Tar, float sSpd)
{
 VECTOR3D NwCoord = Tar - Proj;

 NwCoord.Normalize();
 Proj += NwCoord * sSpd;
}
 

What it does is, it actually "home" into the target/ destined position.
Why I'm doing this?
This gives me more flexability to shoot at other angles.
If my ship moves up or down in a horizontal game
I can easily manipulated my bullets this way.
and second I'm not bound with shooting in one single directions, like 12 o'clock or 3 o'clock,

The second thing I do is.
creating a target position for a bullet.
Code:
// Vertical games
VECTOR3D tPos = ShipPose + VECTOR3D( 0, 800, 0);

For a Horizontal one
I use VECTOR3D( 900, 0, 0)
as the first parameter is for the X, the second for the Y and the last for Z


If you wanted to make a spread shot in a vertical game
Code:
VECTOR3D tPos = ShipPose + VECTOR3D(  50 +(rand(1000) * 0.1f), 800, 0);



Well this is how I do things.
I curious how some of you do it.
 huh1






Be Attitude for Gains
Offline  
Read January 10, 2006, 07:54:56 AM #1
ELLioT

Re: How do you shoot Bullets???

Your way seems just fine to me. Except that if your bullet's speed & heading are constant along tim, there's no need to call the Normalize() on each frame, which is very cpu costly. If that's what you do, I advise you to compute it at the init of the bullet and store the result of "NwCoord * sSpd" instead "Tar".
Btw, isn't "rand(1000) * 0.1f" just equivalent to "rand(100)" with less calculation ?  Wink
Offline  
Read January 10, 2006, 09:59:19 AM #2
RedKnight

Re: How do you shoot Bullets???

Yes is true that
Code:
Normalize();
eating the CPU cycles.

but that depend on what kind of slow moving bullets barrage you're trying to make.


Quote
I advise you to compute it at the init of the bullet and store the result of "NwCoord * sSpd" instead "Tar".
It's seem that I overlooked at this.
good thing you mentioned it. Grin



Quote
Btw, isn't "rand(1000) * 0.1f" just equivalent to "rand(100)" with less calculation ? 
Yes.
Code:
50 - rand(1000) * 0.1f
can gives me random float numbers

Code:
50 - rand(100)
this only gives a random unsigned integers.




Be Attitude for Gains
Offline  
Pages: [1]   Go Up
Jump to:  

Page created in 0.163 seconds with 17 queries.