ooadup Posted July 26, 2014 Share Posted July 26, 2014 Hello, I'm trying to implement ray casting in a top down shooter to have almost very fast bullet speeds. After searching the the forum, I found this example but it has left me with some questions. Is there any way to determine if a Line intersects with a sprite or do I need create lines around each object that can be shot by the player or by enemies? My other idea for a solution to this problem is to loop through each point on ray and determine if there are any sprites at that location. Is there a method that is equivalent to getSpriteAt(x,y) or something like that? Thanks in advance. Link to comment Share on other sites More sharing options...
lewster32 Posted July 26, 2014 Share Posted July 26, 2014 This topic covers (if not fully gets to a solid answer) the same problem: http://www.html5gamedevs.com/topic/7715-raycasting-help/?hl=cast It's really open to how you want to do it, but there's no single in-built solution in Phaser for this kind of functionality outside of the TileMap stuff. Link to comment Share on other sites More sharing options...
ooadup Posted July 26, 2014 Author Share Posted July 26, 2014 (edited) Do you think p2.hittest() would work? Edit for clarity. When I say that I mean, if i did something along the lines of (pseudo code)for (length of line){ var bodies = p2.hittest(linepoint); var wallCollision = false; for (length of bodies){ if (bodies[i].sprite === 'enemy'){ do something } if(bodies[i].sprite === 'wall'){ wallcollision = true; break; } } if (wallCollision){ break; }} Edited July 27, 2014 by ooadup Link to comment Share on other sites More sharing options...
lewster32 Posted July 27, 2014 Share Posted July 27, 2014 I've no idea, I'm not totally familiar with P2. It does have a line shape which you can test for overlap, so maybe you can use that as a makeshift ray? Link to comment Share on other sites More sharing options...
Recommended Posts