Jump to content

Physics rotation colllision


Recommended Posts

Hi there,


I am in trouble with physics, here is my situation:


I have some sort of planet, revolving on top of which a character is running.

Obstacles are spawn and moving with the "planet". They are in a group animated manually.


PROBLEM: collisions work partially: the character can stand on top of the obstacle, but it won't collide the side.


Do you have an idea how I can get full collision with revolving objects ? 

I would prefer to use Arcade to keep it light instead of using P2, but ya know.... will do what it takes.


Thank you folks !



Bits of code:


//OBSTACLES GROUPthis.obstacles = this.game.add.group();this.obstacles.x = this.ground.x;this.obstacles.y = this.ground.y;  this.game.physics.arcade.enable(this.obstacles);this.obstacles.createMultiple(20, 'kit');
//PLAYERthis.player = this.game.add.sprite(BasicGame.gameWidth * 0.5, this.ground.y - this.groundblock1.height - 40, 'thief');this.player.anchor.x = 0.5;this.player.anchor.y = 0.8;this.player.pivot.x = 0.5        this.game.physics.arcade.enable(this.player);this.player.body.collideWorldBounds = true;this.player.body.bounce.y = 0.1;this.player.body.gravity.y = 1500;this.player.body.velocity.x = 0;
update: function () {   this.ground.rotation  = this.items.rotation = this.obstacles.rotation -= 0.01;   this.game.physics.arcade.collide(this.player, this.groundDummy);   this.game.physics.arcade.collide(this.player, this.obstacles, this.somefunction, null, this);
//OBSTACLES SPAWNINGvar obstacle = this.obstacles.getFirstDead();obstacle.reset(this.ground.x, this.ground.y + this.ground.height * 1.1);obstacle.anchor.setTo(0.5,0.5);this.game.physics.arcade.enable(obstacle);obstacle.enableBody = true;obstacle.body.immovable = true; manuallythis.obstacles.add(obstacle);


Note: I don't mind the rotation offset between the sprite and body of the obstacles


Link to comment
Share on other sites

I believe your problem comes from here:

this.ground.rotation  = this.items.rotation = this.obstacles.rotation -= 0.01;

You are using an absolute rotation and not the "physic" one.

When you directly SET the rotation to a value, it quite ignore the physic system during it's travel (even in tiny travel like 0.01).

You have to change the rotation of the planet and objects with a velocity or an acceleration: Something that will not bypass the physic system.



This also explain why you are able to jump on things: Here it's the gravity that moves your player, and the obstable basicaly do not move on the Y axis so the physic system is able to understand what's happening.



You could certainly use 




Link to comment
Share on other sites

thanks a lot ZoomBox,


now how can I use angularvelocity in this specific case where the object is not rotating around it's own center.

I tried to align the anchor point with the "planet" center but then it seems that only the sprite is affected by agularVelocity and not the body.

Have any solution for that one ?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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