Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line of Sight (Ray Tracer) #285

Closed
aaschmitz opened this issue Oct 9, 2013 · 17 comments
Closed

Line of Sight (Ray Tracer) #285

aaschmitz opened this issue Oct 9, 2013 · 17 comments
Milestone

Comments

@aaschmitz
Copy link
Contributor

Given a point x and a point y in the map, we can see if it has a direct view between them without colliding with other objects or solid tiles.

Something like this article:

http://www.codeproject.com/Articles/15604/Ray-casting-in-a-2D-tile-based-environment

This is a fine complement to be used in conjunction with the new collision system #103 ;)

Thanks!

@obiot
Copy link
Member

obiot commented Oct 14, 2013

Thank you very much for the link !

It’s effectively a nice feature to add, however as part of the next 1.0.0 release we do however plan to rewrite the whole collision mechanism using a SAT algorithm, and to use polygon shape object to design the collision layer, which means that we won’t have anymore the current tile based collision as use in this same article.

Which mean raytracing can be added but with a slight different technique :)

@aaschmitz
Copy link
Contributor Author

@parasyte
Copy link
Collaborator

I did a lot of this work for the dynamic lighting in Alienauts : http://blipjoy.github.io/alienauts/public/index.html#debug Specifically, I used the vector methods provided by Chipmunk-js.

Anyway, I am going to need this functionality in Sprung Fever, which does not use Chipmunk-js. So I can't just piggyback off its vector math support.

I don't know if an API can be specified for these things without being too restrictive. Providing the math functions and allowing experienced developers to make use of them is the best approach I know of, as far as interface.

@agmcleod
Copy link
Collaborator

@aaschmitz
Copy link
Contributor Author

Hi @parasyte

The idea is implement a "generic" function with check for object collide between Point A and Point B (returning a array of objects maybe). It is up to the developer to implement a logic to see if the single object that collided is Point B, which would mean a direct target.

In you game Sprung Fever, if one of the girls is on the other side of the wall, the indicator increases, ie you only checks the distance between the player and enemies, ignoring obstacles between them ;)

@parasyte
Copy link
Collaborator

I wrote a bresenham plugin for my LD48 game, live on Twitch. 😖 https://github.com/blipjoy/kungfustar/blob/gh-pages/public/lib/plugins/melonham.js The video shows how I used it. Not the way I imagined in the final game (I'm not going to have time for the rope collisions with the world. Maybe after compo)

@obiot
Copy link
Member

obiot commented Dec 16, 2013

Nice, and I love the name of the plugin :)

@obiot obiot modified the milestones: 1.1.0, 1.0.0 Mar 4, 2014
@aaschmitz
Copy link
Contributor Author

@parasyte Nice plugin, works well for trace collisions with Tiled Collision Layer. But if instead of using the Tiled Collision Layer I need to use Tiled objects, how to check? Or how to get which ObjectEntity is in a certain coordinate of the Tiled map (i.e detect dynamic entities that is not defined in the collision layer)?

@aaschmitz
Copy link
Contributor Author

@obiot obiot modified the milestones: 1.2.0, 1.1.0 Jul 23, 2014
@obiot
Copy link
Member

obiot commented Jul 23, 2014

i guess this one should become easier to implement with the improvements in 1.1.0 (SAT/Quadtree) ?

@parasyte
Copy link
Collaborator

Well, it's still going to be kind of tricky. Assuming your shapes have a minimum width/height (like 10px, for example) you can use that as the step size for the bresenham line generator. That way you're not checking for collisions on every pixel (slow!) but you can still use the polygon hit detection and response vector from SAT to get pixel-perfect collisions along any straight line segment.

@parasyte parasyte modified the milestones: Future, 1.2.0 Oct 15, 2014
@obiot
Copy link
Member

obiot commented Nov 21, 2014

Hi Guys,

What do we do with this one now ? I mean that we show how this is possible using the new collision system, what shall we discuss here ? Add this as a "standard feature" in the engine ?

@aaschmitz
Copy link
Contributor Author

Add it as a "standard feature" in the engine 👍

@parasyte
Copy link
Collaborator

It's good to have, but this is how feature creep sets in. Make it a module add on! #212

@aaschmitz
Copy link
Contributor Author

For tracking with a working example: http://aaschmitz.github.io/melonjs-improved-platformer/

@parasyte Yes, increase the melonJS file size. But, it's a nice feature, and the more features you have, the more complete and distinct is the engine, helping developers :)

@parasyte
Copy link
Collaborator

I agree in part. The point of the modular approach is to provide that completeness without sacrificing usability.

It's like a Swiss Army Knife compared to a Switch Modular Knife; The Swiss Army Knife has fixed utilities, and some of them are big and bulky. The Switch Modular Knife can be resized to fit your needs, and the attachments are interchangeable and configurable; you can even make it big and bulky if that's what you really want.

@obiot obiot mentioned this issue Nov 7, 2017
obiot added a commit that referenced this issue Jan 5, 2018
…ementation

this one was basically coming for free after we added Quadtree +  SAT collision implementation in melonJS.

it can probably be improved or the API tweaked a bit, but it's pretty simple to use already : just cast a line, and get in return an array of intersecting entities.
@obiot obiot modified the milestones: Future, 5.1.0 Jan 5, 2018
@obiot
Copy link
Member

obiot commented Jan 5, 2018

this one was basically coming for free after we added Quadtree + SAT collision implementation in melonJS, not sure why we did not do it back then, except probably because we have too many tickets, and not enough people closing them :P :P :P

@obiot obiot closed this as completed Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants