Hitboxes

Hitboxes

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Hitboxes

Post by FoeOfTheBee »

Now they are spherical, I bet this makes collision detection easy. All you have to do is check the distance of the center point of the sphere from the path of the weapon, subtract the radius of the sphere, and you know if there is a hit if the number is negative.

If the hitbox is a rectagular solid, the calculation would not be so simple. You would have to determine if there is an intersection between the rectangular solid and a line.

The hitbox could also be a cylinder with a hemispherical top and bottom. This might be easier to deal with than a rectangular solid. you would have to calculate the distance between the points ont the two lines and see if at any point it is less than the radious of the cylinder.

I think there may be an economical method to check for the first point in which a line or a ballistic path intersects with a rectangular solid defined as a matrix, but it involves more math than I know at the moment.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Re: Hitboxes

Post by Guessmyname »

Foe OfTheBee wrote:Now they are spherical, I bet this makes collision detection easy. All you have to do is check the distance of the center point of the sphere from the path of the weapon, subtract the radius of the sphere, and you know if there is a hit if the number is negative.

If the hitbox is a rectagular solid, the calculation would not be so simple. You would have to determine if there is an intersection between the rectangular solid and a line.

The hitbox could also be a cylinder with a hemispherical top and bottom. This might be easier to deal with than a rectangular solid. you would have to calculate the distance between the points ont the two lines and see if at any point it is less than the radious of the cylinder.

I think there may be an economical method to check for the first point in which a line or a ballistic path intersects with a rectangular solid defined as a matrix, but it involves more math than I know at the moment.
You're talking about locii, right? (Is this how it's spelt? I can't remember)
User avatar
Felix the Cat
Posts: 2383
Joined: 15 Jun 2005, 17:30

Post by Felix the Cat »

Hmm.

A combination of economy and precision might be a two-phase hitsphere/mesh system.

When a projectile enters the hitsphere, a "potential hit" trigger is set on the projectile, and the extra calculations for possible collision with the mesh are then done. The mesh could be the unit's model or another mesh defined by the modder.

A two-phase hitsphere/hitsphere system might work as well: the modder can define several hitspheres of custom placement and radius for each unit, and Spring generates a "trigger" hitsphere that encompasses all of the unit's real hitspheres. Again, when a projectile enters the "trigger" hitsphere, calculations are done for the real hitspheres.
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Post by Caydr »

Whatever solution, I hope one is implemented soon. I thought the one about multiple hit spheres sounded promising, but being able to use cubes instead or in addition to these spheres would be awesome.

Just looks odd having weapon explosions consistently be in a circle around the unit, not on the unit itself... in addition to the visual thing, there's also the game-breaking factor - a unit which is long and thin should be extremely maneuverable and difficult to hit head-on. Not so in current Spring.
bamb
Posts: 350
Joined: 04 Apr 2006, 14:20

Post by bamb »

a box that stays in one direction, aligned to the world is the cheapest computationally, just multiple if(xdist<xsize) tests, no multiplies or anything.

But the problem with anything else than spheres is that since spring units rotate in all three axes, only spheres stay the same. Other shapes would have to be rotated too before checking and it'd be expensive. (I don't know if too expensive though.)

Maybe a precheck with a box that encompasses all the possible rotated dimensions.
User avatar
Decimator
Posts: 1118
Joined: 24 Jul 2005, 04:15

Post by Decimator »

Even an expensive algorithm could be used, as spheres would still be used for most units.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

Wait... it isn't harder to calculate a collision in a box in 3 dimensions... It's easier then calculated sphere collisions. In order to get any straight line query in a 3D environment you have to do a complicated set of calculations to triangulate one point from the other. To calculate hit collision in a box you only have to measure that all 3 of your of your 3 dimensional points for projectile location are between the highest and lowest points of the 3 box dimensions.

Rotating boxes would be more expensive, but if you're willing to do the triangulation for sphere hit detection they wouldn't be that bad. Elongated spheres would just be scary.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

I think you're facing matrix transformations with a rotating box (multiply with the inverse of the unit's matrix, then do a normal box test), that's not pretty either. Getting an inverse is very expensive I think.

Also hit boxes are rarely used these days , probably because they are almost 50% wider when you attack them diagonally instead of coming from one of their major directions and cylinders work well enough for most things.
Egarwaen
Posts: 1207
Joined: 27 Feb 2006, 21:19

Post by Egarwaen »

KDR_11k wrote:I think you're facing matrix transformations with a rotating box (multiply with the inverse of the unit's matrix, then do a normal box test), that's not pretty either. Getting an inverse is very expensive I think.
Depends. If it's a small matrix, it's no more expensive than any other geometry. If you can guarantee that it's invertible, I think it can be pretty fast. And if you can pre-compute it...

One possible suggestion: make it so hit-geometry doesn't pitch, but just rotates. IIRC, that's what a lot of games (3D shooters, for example) do, and while it leads to some wonky results, it's generally Good Enough. Especially since most units spend most of their time standing straight up and down or at small angles from straight up and down, with a few notable exceptions. (Eg: Spiders in AA) Then you can provide a variety of hit-geometry, from cylinders for humanoid things to rectangles for stuff like tanks, ships, etc.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

Hit geometry has to pitch in FPS because arms don't hang at right angles.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

A rotation matrix could be a 3x3 orthonormal matrix, in which case transpose = inverse IIRC. So it's not really expensive, but I don't think anyone should be implementing this with the messy unit model system that we have today. Cleanup first, then add new features.
User avatar
FireCrack
Posts: 676
Joined: 19 Jul 2005, 09:33

Post by FireCrack »

Dont you mean adjunct/determinant = inverse...

at least that's how I remember it...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

jcnossen wrote:A rotation matrix could be a 3x3 orthonormal matrix, in which case transpose = inverse IIRC. So it's not really expensive, but I don't think anyone should be implementing this with the messy unit model system that we have today. Cleanup first, then add new features.
What's 'messy', out of interest?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Um, things like having s3o and 3DO code mixed in with all sorts of things... the 3DO code, especially, is almost entirely un-abstracted, and is heavily mixed with the animation, BOS-interpretation, and other code sections. In short, it's kind've a mess in there... like a lot've things in Spring, this was obviously built to run first, and to be a model of pretty, clean coding second... and I don't think SJ was really planning ahead for new model formats, etc., when most of this was coded. I suspect when it's all cleaned up, it will help terrifically with certain issues, because file format won't be mixed up with the code that actually moves things around, looks at BOS code, etc.

I'm really overstating the problems to some extent- it's not incredibly awful or anything, but it's quite a bit of layers, and will probably take awhile to get cleaned up.
Theotherguy
Posts: 79
Joined: 11 Jul 2005, 02:01

Post by Theotherguy »

the more I think about hitboxes, the more complicated it seems. I was thinking that it could work by checking to see if the centerpoint of a projectile was coplanar with a side of a hitbox, but then I realized that that would only work if the projectiles couldn't travel outside the box.

couldn't you also do it using diagonals? ie, you could draw a line from each vertex of the box and then use some fancy algorithm to determine whether it lies inside the box?

Then again, I havent programmed anything in a 3d engine and all of my hit detection algortihms focused on brute-force, representing every possible pixel of my 2d game as an element of an array. (a method which was both incredibly slow and prone to errors)
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

I'm really overstating the problems to some extent
IMO you're quite right actually ;)
I did half of an abstraction once already, but didn't continue it and now it's basically unusable because of all the commits. Should go faster next time I try it though ;)
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

@Theothitbox: You need to detect when the projectile is insicoordinatex. For a hitbox that is aligned with the full cordinates, it is easy. abs(projectile.xpos-unit.xpos) <= unit.hitbox.xsize && ...ysize... && ...zsize...

For a hitbox that is not aligned, you would need to do some cordinate transforms on the positions.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Yes and that latter case is what we're talking about with me thinking that that transformation needs a matrix inversion. By the way, the formula for matrix inversion with 3x3 matrices is here. That does look a bit more complicated (i.e. computationally expensive) than simply using cylinders.
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

While looking for the solution I ran across this.

Also, I don't think we need to invert a matrix. All we need to do is find the rotation from unit.FrontDir to [1,0,0], and apply it to (particle.location - unit.location), getting a new location where the easy check for both a cylinder and a rectangular prism apply.

[Edit] Or we could even change it to polar cords, change theta and phi, and transform it back to Cartesian. Of course, all of this should only be done after it has passed a check of a bounding sphere.[/Edit]
bamb
Posts: 350
Joined: 04 Apr 2006, 14:20

Post by bamb »

Jcnossen is right, if the matrix is orthonormal, you don't need to invert costly but only transpose. Proof here:
http://en.wikipedia.org/wiki/Orthogonal_matrix

But that quaternion thing looks good too. Some research could be done.
Post Reply

Return to “Engine”