This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

Hi, does anybody knows how to make collision between hexagonals? The default collision is with rectangles and uses the function touches() in entity.js

```touches: function( other ) {
return !(
this.pos.x >= other.pos.x + other.size.x ||
this.pos.x + this.size.x <= other.pos.x ||
this.pos.y >= other.pos.y + other.size.y ||
this.pos.y + this.size.y <= other.pos.y
);
},
```

i'm looking for something like:

```hexTouches: function( other ) {
return !(
// hex collision
);
},
```

Thanks
You may need a more sophisticated physics engine. Check out Box2D.

Edit: I think I've seen you post around a few Box2D threads already, so I'll assume you've dabbled with it. Does it not do exactly what you're asking?
Edit : sorry my answer was wrong, i removed it.
Hi thanks for the replies.
@Joncom Yes Box2D is pretty good but also heavy, was looking for a more lightweight solution as I just wanted to experiment with hexagons.

@vincentpiel have you experienced with hex on games before? I still can't find a solution, and all what i've found is a check for each edge of polygons like box2d does.

If I find anything will post it.

Thanks
Here's my new favorite resource for all things hexagonal. It doesn't cover collision specifically, however.

Here's another great tutorial about collision and the separating-axis theorem. It doesn't cover hexes, though.

Are the hexes axially-aligned (i.e. they never rotate)? How are you storing their extents, size, position, etc?
Hi drhayes thanks alot for the links.

Well to be honest I just have the idea to make a hex board game but got no code for now. But yes hexes don't rotate. Just wanted to check for example when the player clicks on a hex.
Just talking out of my ass...

If you're just hit-testing you can treat a hexagonal grid as a less dense square grid. If the hexes are flat-topped:

``` __
/  \
\__/
```

Then each hex has a square inside of it:

``` __
/||\
\||/
```

Now you have two cases: did I click within the square in the center of a hex, or did I click within the square made up of the triangles that are the "points" of four neighboring hexes? The second one is the only one that's complex and, even then, it's just got some algebra.
Page 1 of 1
« first « previous next › last »