Impact

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

9 years ago by fourstar07

I'm currently working on a topdown, stealth style game that involves field of vision cones for my enemy entities. The field of vision is working perfectly thanks to the wonderful write up at redblobgames on visibility.

Currently, I'm converting each solid tile in the collision map into a polygon which is then broken into individual line segments that I can use as wall endpoints to cast rays at when performing my visibility cone updates. This works perfectly fine, but is not very efficient. For example, a horizontal wall going from tile (0,0) on the collision map to tile (19,0) will create 20 separate polygons totaling 80 endpoints that will be checked during a visibility cycle. The exact same results could be achieved by checking against a single polygon spanning the entire horizontal width. I'm not encountering any performance issues at the moment, but that's a significant amount of improvement that I'd like to address sooner than later.

My question is whether anyone has tackled converting and merging collision maps to polygons or even continuous line segments from the in game collision map array. I could take what I currently have (which produces a few thousand line segments for all the collision map tiles) and compare line segment endpoints and slopes and combine them as necessary. This would work and I'm not incredibly hard pressed for the efficiency of line segment generation since it's only calculated once on game load, but I feel there must be a better way.

Any thoughts?

9 years ago by Joncom

If you used Box2D, it could handle that collision for you. It does however require more CPU. What sort of frame rate are you getting right now?

9 years ago by fourstar07

Interesting. I hadn&039;t played around with the box2D plugin much, yet. I see that the conversion is automatic and accessible in #ig.game.collisionRects (which definitely solves my initial problem!), but it also seems that sloped collision tiles are converted into rectangular collision boxes with the slope completely ignored. Is there any way around this with box2D?

Framerates are between 45 - 55 at the moment, but I haven't done any kind of performance efficiency throttling, yet (eg; staggering entity visibility calculations to different update tick cycles).

9 years ago by fourstar07

Ok. I just found your updated box2d plugin which looks like it addresses the sloped tile issues. Also found this plugin from the impactplusplus, which I should probably spend some more time with...

9 years ago by fourstar07

For anyone interested in my solution, I decided to forgo using the Box2D plugin. While it actually helped accomplish exactly what I was looking for, it was too much effort at this time to convert the project to utilizing Box2D for all entity phsyics and collision.

What I ended up doing is taking the utiltiles helper module from impactplusplus and plugging it into my game init function. It was pretty easy to include in my project without having to convert into an impactplusplus project and ended up building the most efficient polygonal shapes from the collision map for my purpose of visibility calculation since its shapesFromCollisionMap allows removing the outer boundary edges of the computed collision shapes.

9 years ago by Joncom

Good call. That's the same function that the Box2D plugin uses to convert the collision map into shapes. :p
Page 1 of 1
« first « previous next › last »