hex-engine icon indicating copy to clipboard operation
hex-engine copied to clipboard

Add raycasting functions

Open suchipi opened this issue 5 years ago • 4 comments

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.

suchipi avatar Feb 19 '20 00:02 suchipi

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

andre-lima avatar Feb 23 '20 00:02 andre-lima

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!

suchipi avatar Feb 23 '20 03:02 suchipi

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?

  1. Axis Aligned Bounding Box (detects collision between two rectangles)
  2. Separating Axis theorem (detects collision between two convex polygons)
  3. 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.

Reklino avatar Mar 02 '20 23:03 Reklino

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/

suchipi avatar Mar 03 '20 22:03 suchipi