Sign in to follow this  

bullets in RTS?

This topic is 4111 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 In my 2d-rts i will have guys with guns (duh) and i want fire to be realistic in a way that if you fire in a crowd and miss probably someone else will be hit (and harder to hit in distance etc). So i want "real bullets" My idea is this: 1. Upon firing, missfactor is calculated with shooter skill, weaponStat, distance, targetMovement etc. This factor is then used to randomise angle of the "bullet". 2. Bullet path is calculated with a line (directly, bullets do not live over several frames) and the closest object within this line will be hit. 3. If within view, a trail/line will be drawn between shooter and target. Is this a good idea? And how can i check if a unit(a rectangle) is being cut by a line? Thanks a bunch E

Share this post


Link to post
Share on other sites
Intersection between a line and a quad is fairly simple (naively, it is the intersection between the line and 4 segments, and segment intersection is very well documented on the internet). You can have a look here or here for some math background (and C++ code) - or just google for segment intersection.

Now, your idea is quite good, but using a line/quad intersection might not be precise enough. You can add more precision (but still be simple) by using bounding circles or ellipses (this page has some code about many intersection methods).

Regards,



Share this post


Link to post
Share on other sites
It should work fine.

>> And how can i check if a unit(a rectangle) is being cut by a line?

It depends on your implementation.

If you are grid based, just step along each tile using your favorite line drawing algorithm. If there is a unit in the tile, check for a hit against that particular unit (*see below).

If you are not grid based, you will need to work with whatever spatial system you have created to determine the line that the projectile travels. Once you have that list of sprites, check for a hit against that particular uint (*see below).



(*) When checking intersection...

I believe Emmanuel D's suggestion of using more complex bounding shapes is probably overkill for this style of 2D system.

Just Trace a line through the unit's sprite to see if it hits. Checking against a prebuilt bitmask is very quick especially if your sprites are small. When a shot is fired, you will probably only be checking against a very small number of sprites, so a simple DDA or more complex Bresenham's line algorithm would both work.

Share this post


Link to post
Share on other sites
Then again, a bounding circle (which is in no way complex) might even be easier to implement than pixel perfect checking (which will require you to check pixels along lines and create and keep special colission tiles in memory), as the circle/line intersection is fairly simple to implement.

Share this post


Link to post
Share on other sites

This topic is 4111 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