Jump to content

How to make projectiles in p2 that do not change other entities' velocites


swissnetizen
 Share

Recommended Posts

Hi,

 

I want to make some projectiles that interact with p2-enabled entities (for collision detection) but don't contribute to the entities velocities in anyway. My previous attempt was to have the entities have a mass of 1 > . Unfortunately it causes the collision detection to stop working. I'm not sure what to do now.

 

Note: I'm running 2.2.2 because 2,3,0 has issues with requirejs and 2,4,0 has issues with child entities.

 

Link to comment
Share on other sites

That could work, but I need the entities to be able to collide with each other, I just want my projectiles to not affect their velocity.

Let's take an example: I've got 2 ships, one ship just fired a "laser pulse" at the other ship; obviously the "laser pulse" shouldn't affect the velocity of the 2 ships. I can't make it use a line for collision detection (seeing if the laser actually hit the entity) because the laser isn't instantaneous, I need some space for animation and it would be OP.

Link to comment
Share on other sites

this.bullet.body.sensor = true or something similar.

 

this is how I do it in my game : 

 

this.playersensor = this.player.body.addRectangle(15, this.player.height * 1.2, this.player.width * 0.33 ,0);
this.playersensor.sensor=true;
 
here it's just ts a second shape on the same sprite, the main shape manage the collision, wile the sensor just check if a specific side is colliding, I don't need it to trigger physic response so I set it as a sensor
Link to comment
Share on other sites

every p2 body gets a rectangular shape in the size of the image first..  until you call somesprite.body.setCircle(20);  for example.. then the first shape gets replaced with a circle ;-)

 

yanifska's way is perfect if you want to change the physics body anyway.. that way you can always access the playershape directly by its representation "playersensor" (for example)

 

to acces the first shape of any body you could also do the following:

somesprite.body.data.shapes[0].sensor = true;

as you can see all shapes are stored in the body.data.shapes[] array :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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