Jump to content

How to improve asteroids-movement bullet physics?


buttonsrtoys
 Share

Recommended Posts

I'm writing my first game based on the asteroid-movement example http://phaser.io/examples/v2/arcade-physics/asteroids-movement. The example's great except the physics of the bullets doesn't match the classic arcade game's -- it ignores the momentum of the ship. E.g, below is line 102 from the sample code where the bullet trajectory is calculated -- if the bullet speed is changed from 400 to 200 and the ship is at max speed (also 200) bullets don't "leave" ship.

 



game.physics.arcade.velocityFromRotation(sprite.rotation, 400, bullet.body.velocity);


 

Is there a Phaser call that would incorporate the momentum of the ship? The solution should take into account more the just the speed of the ship since there are lots of times the ship is coasting with the thrusters off and pointing in a different direction than its trajectory.

Link to comment
Share on other sites

I ended up just adding the XY of the ship to the bullet. Work's great.

// adjust the bullet trajectory by the ship's trajectorybullet.body.velocity.x = Math.cos(bullet.rotation) * BULLET_SPEED + ship.body.velocity.x;bullet.body.velocity.y = Math.sin(bullet.rotation) * BULLET_SPEED + ship.body.velocity.y;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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