Replies: 2 comments 2 replies
-
Hi @ivasilov One way of implementing line of sight is to use If you make something following that article please do share! It would be pretty awesome to have an example in excalibur! Here is a very rough example of how to use the built in raycasting in excalibur: const box = new ex.Actor({x: 100, y: 100, width: 100, height: 100});
const ray = new ex.Ray(ex.vec(0, 0), ex.Vector.fromAngle(Math.PI / 4))
const maxLength = 100; // pixels
// Returns vector (50, 50) that is the top left corner of the box actor
const maybeCollisionPoint1 = box.collider.get().rayCast(ray, maxLength);
// Returns null when no collision when ray casting only 10 pixels
const maybeCollisionPoint2 = box.collider.get().rayCast(ray, 10); I have some really old code we made for ludum 29 that does some simpler line of sight that probably would need some updating to work with latest excalibur. The gist of this code is it ray casts looking for the kraken box geometry every update(). The game link, you can drop |
Beta Was this translation helpful? Give feedback.
-
I used https://github.com/Petah/2d-visibility i rewrote it a little to use excaliburs Vector instead of their Point. I take my tilemap and I extract only those tiles that are solid and only around the player, I extract colliders from those, that way I get polygons that I use for the algorithm. Output is used to build the shadows my game has all around the player sight, but you can easily change the line of sight by "building" fake walls before giving it to the algorhitm and ofc you can use output of the algo to check collisions with other objects to see if they are in your sight or not |
Beta Was this translation helpful? Give feedback.
-
Hey, does anyone knows if there's a simple way to implement line of sight (https://www.redblobgames.com/articles/visibility/)?
Any ideas on how I would implement this?
Beta Was this translation helpful? Give feedback.
All reactions