Doug Posted April 23, 2018 Share Posted April 23, 2018 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 More sharing options...
snowbillr Posted April 23, 2018 Share Posted April 23, 2018 I'm pretty sure you can just set the property `angle` or the property `rotation` on the an Arcade physics body. I believe `rotation` uses radians. lumosmind 1 Link to comment Share on other sites More sharing options...
Doug Posted April 23, 2018 Author Share Posted April 23, 2018 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 More sharing options...
snowbillr Posted April 23, 2018 Share Posted April 23, 2018 I just played with a simple example in the labs and it seems like if you do a `t.angle = 30` it should work. But looking at the source, I don't understand why... Link to comment Share on other sites More sharing options...
snowbillr Posted April 23, 2018 Share Posted April 23, 2018 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 More sharing options...
Doug Posted April 23, 2018 Author Share Posted April 23, 2018 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; Link to comment Share on other sites More sharing options...
digitsensitive Posted April 23, 2018 Share Posted April 23, 2018 This question has already arised on github: https://github.com/photonstorm/phaser/issues/3570 It won't work with Arcade Physics, use Matter Physics instead. Link to comment Share on other sites More sharing options...
Doug Posted April 23, 2018 Author Share Posted April 23, 2018 Great thank you. Will do. Link to comment Share on other sites More sharing options...
snowbillr Posted April 23, 2018 Share Posted April 23, 2018 Glad there was a real answer here, sorry I was feeding you bad information! Link to comment Share on other sites More sharing options...
Doug Posted April 24, 2018 Author Share Posted April 24, 2018 No problem at all. I really appreciate that you tried. Link to comment Share on other sites More sharing options...
Recommended Posts