Jump to content

EnemieFollow


NikoFenix
 Share

Recommended Posts

Hello how are you, I'm developing a rpg game and I'm in the development of enemies, in short my problem I have an enemy (spider) that is dedicated to securing the player, but I can only ahcer follow the mouse, some solution ? My code is

PRELOAD 

<  game.load.image('ball', 'Multimedia/Imagenes/Personajes/spider.png');  >

CREATE

    game.physics.startSystem(Phaser.Physics.ARCADE);

    balls = game.add.group();
    balls.enableBody = true;

    for (var i = 0; i < 50; i++)
    {
        var ball = balls.create(game.world.randomX, game.world.randomY, 'ball');
    }

 

 ------------   HERE IS THE PROBLEM ---------------

UPDATE

       if (w.isDown || a.isDown || s.isDown || d.isDown)
    {
        //  First is the callback
        //  Second is the context in which the callback runs, in this case game.physics.arcade
        //  Third is the parameter the callback expects - it is always sent the Group child as the first parameter
        balls.forEach(game.physics.arcade.moveToPointer, game.physics.arcade, true, 200);
    }
    else
    {
        balls.setAll('body.velocity.x');
        balls.setAll('body.velocity.y');
    }
    

 

 


        

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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