Open Draknek opened 13 years ago
As all the current hitboxes are based on width and height it may be easier to add oval hitboxes.
Detecting intersection of circles is simpler than ellipses, so I'd probably restrict it to circles and have width=height=diameter.
The code isnt that much more complex (about 10 more line in total as i implemented it) its the same test but with a scaled distance function.
Can you post your code please? I don't believe it is as simple as that. An example of a problematic setup: http://www.draknek.org/misc/ellipses.svg
Yes your right I made a stupid assumption about ellipses.
I do have the code to work this but it is quiet a bit longer (Mostly forming a particular quartic then fiddling the discriminate around). Probably best left out for now.
On another note might it be a better idea to separate the notion of a bounding box out of the hitbox and make the hitbox just a mask (defaulting to the bounding box)? That would allow more flexibility for the shape (for example to allow for rotation). But it would be a big api change so may not be best way of going forward.
Have a current version here https://github.com/cipher05/FlashPunk/commit/bca9118df7aa1b9f8e317bb225edc883d51785cc
Does it look ok?
That won't correctly handle some collisions, e.g. circle-vs-pixelmask.
As far as implementations go, I was imagining a CircleMask
class rather than adding a circular
property to Entity
. Not actually sure which would be better though. If circles were just another type of mask, it means a lot of code will just automatically work. But if there's support at the entity level then circle-circle collisions can be really efficient.
I certainly don't think setHitbox
should be extended in that way. If we want a convenience function for setting a circular hitbox, it should be a separate function.
This handles circle-circle collisions properly, but that is it. Everything else it treats as a square hitbox. Also, the renderDebug is not quite right. But it's a start.
This is untested against anything other than other circles and hitboxes.
This is a very common requirement, it should be built-in to FlashPunk.