hex-engine
hex-engine copied to clipboard
Add raycasting functions
Hex Engine should include some ray-casting and collision detection functions out of the box, that use information from the Geometry component. I haven't written them already because I don't know much about ray-casting or which formulas are commonly used to implement it effectively. I would definitely appreciate some help with this.
I don't know how the best pratices for raycasting are either, but I did develop one prototype for use with the Kontra game engine.
Here's the link for the demo, with the link for the code inside: https://kontra-experiments.netlify.com/ Also, a discussion about the experiments which may inspire you for other features: https://github.com/straker/kontra/issues/136
Thanks for sharing! I will take a look. Hex Engine's raycasting requirements aren't exactly the same as Kontra's (since entities can be non-rectangular), but I can probably get some good inspiration from your Ray
class. Thanks again!
Yo! Pretty new to game dev, so excuse my ignorance 😅.
I've been doing some light research on collision detection. Would it be accurate to say that we'd want to support these three types of collision detection?
- Axis Aligned Bounding Box (detects collision between two rectangles)
- Separating Axis theorem (detects collision between two convex polygons)
- Circle Collision( technique that detects collision between two circles)
1
and 3
seem simpler to solve: MDN collision detection
2
seems a way more complex, but this lib looks promising.
Yup, that sounds about right; though we'd also need to support collision between circles and polygons (and vice versa). But we can use circle-like polygons to do that, if needed.
Thanks for the links! They'll be super helpful.
Something else that may be useful is this library, which decomposes an arbitrary polygon into its convex pieces: https://github.com/schteppe/poly-decomp.js/