Jump to content

Physics.P2 moving sprite


oleg90990
 Share

Recommended Posts

Hello everybody!

I'm having trouble.

I do for yourself the game, and I need to have the tank cars are not repelled from himself but only pushed without accelerating.

An example can be seen here http://46.17.40.56

 

Part of the tank code:

this.tank = game.add.sprite(x, y, 'tank');
this.tank.bringToTop();
game.physics.p2.enable(this.tank);
this.tank.body.setCollisionGroup(playerCollisionGroup);
this.tank.body.collides(mapCenterCollisionGroup);

Part of the car code:



groupCar = game.add.group();
groupCar.enableBody = true;
groupCar.physicsBodyType = Phaser.Physics.P2JS;


for (var p = 0; p < map[id][position].length; p++) {

    name = map[id][position][p].name
    x = map[id][position][p].x
    y = map[id][position][p].y

    sprite = groupCar.create(x, y, name);

    sprite.id = id;
    sprite.angle = map[id][position][p].angle;
    sprite.static = map[id][position][p].static;
}


groupCar.forEach(function(car) {
        car.body.setCollisionGroup(carCenterCollisionGroup);
        car.body.collides([playerCollisionGroup, bulletCollisionGroup, carCenterCollisionGroup]);
        car.body.static = car.static;
        car.body.angle = car.angle;
        car.body.kinematic = false;
})

 

In the documentation, or in the examples I have not found help, I hope you help me

 

P.S.

Sorry for my bad english:(

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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