Jump to content

Overlap Function Not Working Properly on Rotated Object? (Arcade Physics)


BreezySparrow
 Share

Recommended Posts

Hi,

I'm currently trying to implement a rotating pong-paddle esque object that can deflect bullets being fired at it, and have a custom overlap function defined to handle collisions. 

	this.physics.arcade.overlap(this.board, this.bullets,
			this.boardVsBullet, null, this);

When the paddle is not rotated, the function works as intended.

However, when the paddle is rotated, the bullets seem to go straight through the paddle; I have tried debugging and inserting breakpoints, and "this.boardVsBullet" does not seem to be getting called at all when the paddle is rotated. People I am working with seem to think it's an issue with Arcade physics, but I'm not as sure. Is this a known issue with the engine or there something else I can try checking for?

Link to comment
Share on other sites

You can try to inspect your physics body in the render function to check what happens with your physics body. In arcade physics, your body will remain axis aligned in case of rotation, this is not the case for P2 physics:

see this one (arcade):

vs this one (p2):

 

Link to comment
Share on other sites

It kind of depends on your game setup. Do you have any printscreen of it to see what is going on? What I have done before is: you might be able to change the dimensions of your physics body to match your object motion:

pingpongPaddle.body.setCircle(45); // makes a circular body
pingpongPaddle..body.setSize(45,45,0,0); 

http://phaser.io/docs/2.4.4/Phaser.Physics.Arcade.Body.html#setSize

 

Link to comment
Share on other sites

bOwzRvX.png

Here's a quick screenshot of what happens when I try to rotate the paddle (center point is the player object in the middle).

I'm currently experimenting with trying to set the size and shift it to a point where it'll just stay rotating around the player but I can't seem to get it to stay relatively close to the board sprite location.

 

Link to comment
Share on other sites

You could try is to set a circular body at the player its centre and slightly adjust the width of each paddle so that it will always lie within the circle, sort of like this:

circle.png.e454fdd6503d4e04e90a3d4eb5c46af4.png

If the bullets/ the game is fast enough, then the user will probably not notice the deflection behaviour. However, the bullets mights not deflect the way you would like them to, so you might have to manually calculate the deflection(in your boardvsBullet function) depending on how what angle the bullet approaches the body. It can also collide with the back, which might not be desirable.

I think in your case it would be better to use P2 physics. Its just a matter of changing the system so you don't have to do anything special for it. It will be more expensive when looking at performance so you have to consider that.

Link to comment
Share on other sites

The player will have to be vulnerable to the bullets/balls in the final build so I probably will have to rewrite to use P2 physics. Searching the forums seems to indicate there's a lot of simple ways to create a custom overlap physics functions such as this one. If I understand correctly I would just need to have all my "collision-handling" functions respond to something like that instead?

Link to comment
Share on other sites

Yes there is a nice example on how to achieve this too:

https://phaser.io/examples/v2/p2-physics/impact-events

You can even set your own collision groups so that you can decide what/who will be involved in certain collisions:

https://phaser.io/examples/v2/p2-physics/collision-groups

Note though that the phaser weapon plugin uses arcade physics, so in case you are using phaser.weapon, be aware of that. But if you have made your own bullet spawning system, implementing P2 will be straightforward.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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