Jump to content

Ray Casting and P2 for semi-realistic bullet speeds.


ooadup
 Share

Recommended Posts

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

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 by ooadup
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...