Jump to content

Rotating GameObject & Collider


locojoetive
 Share

Recommended Posts

Hello everybody,

I am new to Phaser and thought why not start with Phaser 3.

My program dynamically changes the rotation of a box and I wanted the collider to rotate as well, but I didn't find how to archive this.

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600, //window.innerHeight;
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 300 },
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

//...

function create() {
   //...
   blockAU = blocks.create(200, 200, 'block');
   //...
}

function update() {
   //...
   if(rotateLeft)
       blockAU.angle -= 1;
   else
       blockAU.angle += 1;
   
   blockAU.refreshBody();
   //...
}

I didn't find examples for this, and the API and Docs where pretty confusing. Maybe I am using the wrong terminology when searching.

I really hope you can help me with this :)

 

ColNotRot.jpg

Link to comment
Share on other sites

Hello samme,

Thank you for your fast reply. I replaced block.angle with block.rotation, but get the same results. The link you posted about the rotation of a body says:

" It doesn't rotate the Body's boundary, which is always an axis-aligned rectangle or a circle."

Does this mean it isn't possible to rotate a rectangular body with the Arcade Physics?

Link to comment
Share on other sites

  • 1 year later...

hm ...

probably not how it's done as i never 'learned' anything but by myself so i tend to go with my way and what works :

 

this.spikes = this.physics.add.staticGroup();
    if(leveldata[6]){
        console.log(leveldata[6]);
        tmp = leveldata[6].split('-');
        for(let lus=0;lus<tmp.length;lus++){
            let spikedat = tmp[lus].split(':');
            let spikerot = spikedat[1];
            let spikepos = spikedat[0].split(',');
            console.log(typeof spikerot);
            switch(spikerot){
            case '0':
            case '2':
            console.log(spikerot);
            this.spikes.create(spikepos[0],spikepos[1], 'spikes').setSize(50,34).setOffset(10,0).setAngle(spikerot*90);
            break;
            case '1':
            case '3':
            this.spikes.create(spikepos[0],spikepos[1], 'spikes').setSize(34,50).setOffset(20,-10).setAngle(spikerot*90);//body.rotation not working or im doing it wrong
            break;
            }

        }
    }

screenshot :

screenshot of scene ingame (OGA1 : Oga is the new Crack : get things moving) #opengameart

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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