# 2D burst shot

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

## 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 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 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 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 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.

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 13
• 53
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009553
• ### Who's Online (See full list)

There are no registered users currently online

×