Jump to content

Search the Community

Showing results for tags 'distancebetween group'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hey. I want to trigger different events depending on the distance between a member of a group (enemies) and my avatar (player). Basically, I want the enemy to 'aggro' if it's < 200 distance, and 'kill' my player if the distance is < 50. I tried to achieve this with 'arcade.overlap()' and 'arcade.collide()' but I can't seem to trigger different events based on the 'depth of the collision' (offset?). var game = new Phaser.Game(640, 960, Phaser.AUTO, '', { preload: preload, create: create, update: update});// GLOBALSvar enemies;var robot;var player;var text;var counter = 0;var xPos; // randomly generated x coordinate of robotfunction preload() { game.load.image('player', 'assets/laserpoint.png'); game.load.image('robot', 'assets/tewst.png'); }function create() { game.physics.startSystem(Phaser.Physics.ARCADE); // ENEMIES GROUP enemies = game.add.group(); enemies.enableBody = true; enemies.physicsBodyType = Phaser.Physics.ARCADE; enemies.createMultiple(20,'robot'); // PLAYER AVATAR player = game.add.sprite(game.world.width/2,game.world.height /2,'player'); game.physics.enable(player, Phaser.Physics.ARCADE); player.anchor.setTo(0.5); // COUNTER ++ IF COLLISION OCCURS text = game.add.text(game.world.centerX, game.world.centerY - 300, 'Counter: 0', { font: "64px Arial", fill: "#ffffff", align: "center" }); text.anchor.setTo(0.5, 0.5); // LOOPED TIMER SPAWNS MOB this.timer = this.game.time.events.loop(500, spawn, this); }function update() { // PROBLEM if (game.physics.arcade.distanceBetween(enemies,player) < 100) { text.setText('Counter: ' + counter); counter++; } // I've tried (robot,player) too, no luck. } // SPAWNS ENEMY ROBOT AT RANDOM X COORDINATEfunction spawn() { xPos = game.rnd.integerInRange(1,510); robot = enemies.getFirstExists(false); if(robot){ robot.reset(xPos,200); robot.body.velocity.y = 200; robot.anchor.setTo(0.5); }}
×
×
  • Create New...