swissnetizen Posted May 23, 2015 Share Posted May 23, 2015 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 More sharing options...
icp Posted May 23, 2015 Share Posted May 23, 2015 Set the entities bodies to kinematic:this.body.kinematic = true; Link to comment Share on other sites More sharing options...
swissnetizen Posted May 25, 2015 Author Share Posted May 25, 2015 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 More sharing options...
valueerror Posted May 25, 2015 Share Posted May 25, 2015 just configure the bullets to act as sensor.... they will not trigger a collision response but still report the collision.. so you could then change the health of the enemy and destroy the bullet but no physics response will occur ! Link to comment Share on other sites More sharing options...
swissnetizen Posted May 25, 2015 Author Share Posted May 25, 2015 How would we do that? Link to comment Share on other sites More sharing options...
Yanifska Posted May 25, 2015 Share Posted May 25, 2015 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 More sharing options...
valueerror Posted May 25, 2015 Share Posted May 25, 2015 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 More sharing options...
Recommended Posts