Sign in to follow this  
Mariusz

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

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

Share this post


Link to post
Share on other sites

If the order isnt crucial in your game, the easy fix is to enable P2 first, then use sprite.body.angle only. Dont use sprite.angle

Otherwise sprite.angle set before P2 enabled seems to be acting like a permanent angle offset and that will probably cause all sorts of headaches.

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.