Sign in to follow this  

2D burst shot

This topic is 4717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, im working on a 2D online RPG and am trying to implement the SMG into the game. bsaically, i want to be able to fire 3 bullets, each lined up with each other, one slightly ahead of the other. heres a pic to show what i mean: the red boxes are players. the guy on the left fired his SMG to the guy to the upper right. the 3 white balls are the burst shot.. this is what im talking about.. anyway, i can calculate the strait path from the guns barrel to the target, and have it fly in the strait path there. my question is, what is the cheapest and easiest way to find the starting positions of the positions of the 3 bullets? if i fired one bullet, its starting position is the edge of the barrel of the gun. if 3 burst shots are fired, one bullet starts at the edge of the gun, another is slightly "ahead" of that one, and another is slightly ahead of that one again. how do i calculate these 2 "ahead" positions? i guess i could fire 3 individual shots over time, but im trying to conserve on bandwith and only send a packet saying "a burst shot was fired" rather then sending 3 packets saying "a bullet was fired". sorry if this is a stupid question, im mathmatically retaded. thanks for any help. NOTE: a bullet can be fired in any direction, 360 degrees

Share this post


Link to post
Share on other sites
You could have a mode (state) set to burst and when it is set to burst it sends the packet that receives it as a burst and does the damage.

And i doubt it would cause trouble to send those packets.

Share this post


Link to post
Share on other sites
You could have a packet that says "a burst was fired", and then both the client and server fire them one at a time.

You could also say they fire every t milliseconds and pretend that the gun was fired 2*t ms ago. Then you get:

//bullet*.vel would all be the same, the speed of a bullet in the direction to the enemy
//this one went for two time periods at the speed of a bullet
bullet1.pos = player.pos + 2 * t * bullet1.vel;
//this one was in the gun (at player.vel) for one time period and was in projectile motion for one time period
bullet2.pos = player.pox + t * player.vel + t * bullet2.vel;
//this one was in the gun for two time periods and was just fired
bullet3.pos = player.pos + 2 * t * bullet3.vel;

I think it's a lot easier to just have one packet signal a burst shot and have the client and server each fire staggered shots.

Share this post


Link to post
Share on other sites
If you are calculating the components of your vectior via Pythag:

dist = SQRT(dx*dx + dy*dy)

//normalize
vec.x = vec.x/dist
vec.y = vec.y/dist

To calculate the start of bullet2:(ten units radius)

bullet2.x = start.x + 10* vec.x
bullet2.y = start.y + 10* vec.y

if you are using angles:

float angle = atan2(dy,dx)

vec.x = cos(angle)
vec.y = sin(angle)

then just :

bullet2.x = start.x + 10* vec.x
bullet2.y = start.y + 10* vec.y


Share this post


Link to post
Share on other sites
You could always decide only to send a "shooting burst" message, and the client would generate the 3 bullets on its own, while the server would also generate them.

Share this post


Link to post
Share on other sites

This topic is 4717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this