Jump to content

Move towards the object


zelcard
 Share

Recommended Posts

Greetings,

 

I recently started working in Phaser and it seems like a pretty good framework, for practice I started working on simple top down shooter game and now it seems I have a problem with move toward the object functionality (enemies moving toward player), I have tried few solutions including all from this post:

 

http://www.html5gamedevs.com/topic/3441-movetoobject-help/

 

but I was unable to make it work, I'm complete noob and probably doing something wrong but I cant figure out what, so I hope some you guys can help me out, thanks in advance. :)  Here is the part of code I have done so far:

 

function create() {    game.world.width = 800;    game.world.width = 600;    game.physics.startSystem(Phaser.Physics.ARCADE);    bullets = game.add.group();    bullets.enableBody = true;    bullets.physicsBodyType = Phaser.Physics.ARCADE;    bullets.createMultiple(50, 'bullet');    bullets.setAll('checkWorldBounds', true);    bullets.setAll('outOfBoundsKill', true);        player = game.add.sprite(400, 300, 'arrow');    player.anchor.set(0.5, 0.5);    game.physics.enable(player, Phaser.Physics.ARCADE);    player.body.allowRotation = false;        enemies = game.add.group();    enemies.enableBody = true;    createEnemies();}    function createEnemies ()     {    for (var y = 0; y < 2; y++)    {        for (var x = 0; x < 5; x++)        {            var enemy = enemies.create(game.world.randomX, game.world.randomY, 'enemy');            enemy.anchor.setTo(0.5, 0.5);            enemy.body.moves = false;        }    }}    function update()  {    player.rotation = game.physics.arcade.angleToPointer(player);    if (game.input.activePointer.isDown)    {        fire();    }    game.physics.arcade.overlap(bullets, enemies, collisionHandler, null, this);}

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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