Doug

Rotation of arcade physics body

Recommended Posts

Hi

Forgive me if I've missed this, but I can't find it in any of the documentation.

Is there a way to specify the the rotation of an arcade physics body?  I can rotate the game object image, but that has no effect on the physics body.

I would have expected a .setAngle or .setRotation method to be available on Phaser.Physics.Arcade.Body.

Seems such a simple one to miss, but I keep needing this and having to use matter, which is just a little more fiddly.

Thank you!

Share this post


Link to post
Share on other sites

Thanks.  I tried this, but it doesn't work.  I tried the following:

let t = this.physics.add.sprite(100, 100, 'sprites', 'windSock_0000');
t.body.rotation = 1;

...and

let t = this.physics.add.sprite(100, 100, 'sprites', 'windSock_0000');
t.body.angle = 30;

Interestingly it doesn't give an error.  It just does nothing.

I also tried with image and staticImage gameobject types.

Do you think this is maybe a bug?

Share this post


Link to post
Share on other sites

Okay. So it looks like you can rotate any GameObject with `angle` or `rotation`: https://github.com/photonstorm/phaser/blob/master/src/gameobjects/components/Transform.js

And the Arcade Physics Body uses that value from the GameObject for its physics - https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/Body.js#L863

So TL;DR set the rotation on the game object, and arcade physics will use that when it does its calculations for the body.

Share this post


Link to post
Share on other sites

Thanks, that's really kind of you.  Just did the same to check it and it still fails here.  It rotates the game object, but not the physics body.

let t = this.physics.add.sprite(200, 200, 'sprites', 'windSock_0000');
t.angle = 30;

 

Screenshot from 2018-04-23 15-59-53.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.