Trying to create powered wheel with Matter physics

Hello,

I’m trying to make a wheel that realistically rotates and moves along the ground in Phaser 3.23 beta using the built-in Matter physics support.

From my research so far it looks like I need to be setting the angular velocity of the wheel, and everything else should happen automatically. However, the wheel remains completely stationary. It is not a static body (if hit by other objects it moves as one would expect).

This is the code I’m trying to test right now:

        let velocity = 0.05; // 0.05;
        velocity = Phaser.Math.Clamp(velocity, 0, 1);

        const body = sprite.scene.matter.body;
        // set angular velocity to wheels
        body.setAngularVelocity(sprite, velocity);
        console.log(sprite.body.angularVelocity);

The console statement repeatedly prints 0, despite the angular velocity being set on the line above.

I’ve been looking around several different forums/sites for several hours now and I’m sure I must be missing something basic, but I’m not sure what. Most of the resources I’ve found are for the standalone version of Matter or Phaser’s arcade physics.

Does anyone know what I’m doing wrong?

Hi @embeddedt, you are right, setting angular velocity should get you the result that you desired.

Tell me have you set the physics shape of the body to a circle?
It goes something like this: sprite.setBody({type:'circle',radius:43})

I see that you are taking the body of the sprite like sprite.scene.matter.body, you don’t have to do it like that.

If you created your sprite like say,
let sprite = scene.matter.add.sprite(x, y, "texture")
https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Matter.Sprite.html

Then you can just set the sprite’s angular velocity like,
sprite.setAngularVelocity(0.05);

Also I found this article on setting angular velocity to a football online, it should be helpfull.

Thanks for the reply. I’ll give your suggestions a try later today. I have turned on the debugging outlines and I do see that it is a circle. It would have been nice if it was that simple though! :slightly_smiling_face:

Thanks for the tip on calling setAngularVelocity directly; I’ll try that.

Calling sprite.setAngularVelocity instead of sprite.scene.matter.body.setAngularVelocity is working perfectly; thanks so much!

1 Like