Jump to content

Enabling physics body in P2 completely ignores the sprite's rotation.


Mariusz
 Share

Recommended Posts

Hello there. I've been playing with the P2 physics engine and I hit a brick wall. If I try to enable P2 body on a sprite that is already rotated, the physics body will create a body rectangle that matches the sprite's rotation AND set the sprite's rotation to 0. I made the following gif to illustrate the issue: 

 

http://www.gfycat.com/AdolescentBruisedCuscus

The scale of the dynamically created sprite seems to be preserved perfectly fine, it's just the rotation that's been baffling me. I looked briefly into phaser.js, but couldn't pin it down... Could somebody explain to me what's going on? 

Thanks in advance
Mariusz

Link to comment
Share on other sites

Hey Rudy, thanks for the response. What I want to be able to do is enable the user to start drawing a line upon left mouse button click and keep manipulating the shape until the button is released. Once the user is happy with the length and angle, they will release the button and, at that point, I want to assign a physics body to the object that will acquire all the aforementioned properties, i.e. the length and the angle. So yes, to address your question, the order is crucial in this case. 

Unless there is a better way to approach this problem? 

 

Edit: My bad. I actually put some thought into Rudy's idea and it works perfectly fine. The sprite is manipulated and upon click release, I store the desired rotation, reset the sprite's rotation to zero and then apply it using sprite.body.angle. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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