Jump to content

Rotation of arcade physics body


Doug
 Share

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!

Link to comment
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?

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

Link to comment
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

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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