NikoFenix

EnemieFollow

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');
    }
    

 

 


        

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.