Pre-Order the Game!

Desura Digital Distribution

Monday, February 27, 2012

A hit! Or is it?

While I grappled with the idea of rectangle vs circle collision (which was kinda demotivating...), I decided to scrap the rectangle, and only have line vs circle. The reason is that with rectangles, it's possible to hit one circle more than two times, and there's no easy way of making it only two hits (entry and exit points). A line is guaranteed to have at most two points of intersection with a circle, which simplifies my life a lot. The downside to this is that if you have a huge laser cannon of doom that fills up half of the screen, it'll only collide with ships that are in middle of the beam. You can go around this by spawning a lot of lines close together, the neat side effect will be the visual effect of some ships blocking part of the beam.

With this decision made, I then added line vs circle collision, have it detect all points of impact, then sorted the list of collisions. I then added script support for "OnHit" on the equipment being hit, and "PostHit" on the particle doing the hitting. It's not done yet, the line vs circle collision isn't working quite right, and I need a way for the particle to tell the game "The shield was too strong for me, I'm done here", so it don't continue processing the rest of impacts.

OnHit is done by calling the equipment that's being hit, and have it modify the values (for example, shield would reduce the damage) of the particle, and spawn any visual effects (shield ripple effect for example)

After the OnHit call is made, it then calls the particle's "PostHit" with the new values, and see if it's done or should spawn any other particles (such as a fragmentation shell that bursts into shrapnel). If it's not done, then the loop continues with the next round of "OnHit" and "PostHit" with the next equipment in list. It continues until the particle is done, or there's no more collisions.

Now for the screenshots of this in action! First one is the laser beam particle missing as a reference:



The next screenshot is of it "hitting" (line vs circle algorithm isn't correct, will need to fix that), it shows that it spawns two shield particles (was supposed to be "entry" and "exit" points, with exit eliminating the remaining damage from the beam) and the beam was cut off:



I can almost taste the victory! This scripting system is almost done! Just need to polish up a few things, fix the line/circle collision algorithm, fix the sorting algorithm, then add a simple projectile weapon to test a projectile-type weapon, then this part is done! There's still a lot more to be done, but for the purposes of "playable", it'll be done until I come back to add missiles and other goodies.

After that, it's tutorial, then I'll release a new version for the pre-orderers!

2 comments:

  1. I am not sure what is the problem with the "shield was too strong for me" situation?
    If I understand correctly you modify damage value on every collision - so what's the problem with setting it 0?

    Similarly unclear what is the problem with the super-duper-mega laser doom-cannon? Don't you have collision check for every line you draw? Why don't you just distribute the damage among them?

    The last question: from your weapon concept it is clear, that you can easily shoot on your own ships. Is that true for projectile weapons as well? Or will there be an enemy/friend identification for them? Maybe as a development possibility? Or a separate weapon class?

    ReplyDelete
  2. What I meant is that if you shoot a laser, and the game finds 6 collisions. However after the third collision, the laser is "done" meaning that it has inflicted all of its damage, and is not continuing. But the game continue to process the remaining 3 collisions despite the laser being done. Sometimes some weapons don't use damage to determine whether or not it's "done". So it will need to be a separate boolean value to tell the game to stop processing the remaining collisions. For example, Wacky Cannon will stop processing after the first ship collision, it would bypass all the shields.

    As for the "Super-duper-mega laser doom-cannon", if the beam is 200 pixels thick, the collision detection only use a line that's 1 pixel thick, leaving out 199 possible collisions (aka rectangle vs circle rather than line vs circle). But if you have the script spawn 50 lines spaced 4 pixels apart, with 1/50 of the damage for each line, then it'd be more accurate representation of "Super-duper-mega laser doom-cannon". You can then see the advantage of having a highly dense beam against a strong shield, or a wide-focus low-damage against a bunch of missiles/smaller ships.

    Yes, both beam and projectile weapons can hit your own ships. I think it's possible to add "Enemy/Friend Identification" by passing in a list of ships in the combat zone, and seeing if the bullet collides with a friendly ship. No promise though, but I'll at least look into it. For missiles/torpedoes, part of the reason why they're being added after release is that they will have pathfinding, and they don't hit their target in one turn, unlike the regular weapons. So I think it'd be possible to script a missile to act like a smart bullet.

    Again, the goal is to have a highly moddable space combat. For now, when beam/projectile are working, and collision detection/damage/ship death are fully implemented, then I'll leave it until after release.

    ReplyDelete