Search the Community

Showing results for tags 'collision'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 497 results

  1. Collision between sprites

    Hello, I'm developing my first application with pixi.js 4 and I have a problem with collision between sprites. In my case I use textures with irregular shapes and logically I'm able to intercept collision between rectangular sprites (using Bump library). I need instead to check collision between irregular shapes as attached example. Is there a way to create an impostor shape attached to sprite in order to have this result? Thanks for now and sorry for my bad english. Vittorio
  2. Hi !! I continue to learn this wonderful framework of BabylonJS and program an open source FPS game (should be on Github soon). I first hesitated between built-in collision system and the cannonjs physic engine : I tried both and I currently think the physical engine will better suit my needs (rocket jump ! ). I am already able to move a character, in any direction, first or third camera view, I can jump on objects, but I am facing a new problem.... => I have to detect ANY ground collision and this task is not so easy as it seems. Detecting collision with a cube is easy, but detecting collision ONLY from the top of the cube (to end a jump andplay a sound, for example) is more complicated. If I jump, I don't care about wall collision with the cube, I am interested only by the collision when my character collides from bottom. My character is a simple invisible Box. So I got some ideas : 1) create a second box for my character, a little bit smaller, just to detect collision "from bottom". xxxx xxxx <=== main box, detect wall collision xxxx ----- <=== thin bottom box of the character, detect ground collision 2) OR change scene objets where I can jump on, with a special "ground type objet" but this solution seems the most awful possible : you are not free anymore to design objects 3) OR change the way collision are detected : for example, if my position.y is decreasing AND THEN my position.y < epsilon, then it means I have collided something. With this solution I don't even need collision event : i create it myself, but it is a little but tricky to code OR ... any idea ? I will try solution 1 and will share my experience here. If anyone has an advice on this or encountered the same kind of problem plz tell us Thanks
  3. Hey guys, I'm new to phaser and I'm not quite sure if this is a bug or a mistake of myself. In this code if the player has a circle as his body and if he is colliding with one of this obstacles he won't get separated as it is described in the phaser documentation. So if you move up and collide with the obstacle the console starts printing out true even if you stop moving. In addition to that if you walk against an edge of the obstacle the player gets stuck on it and can't get away of that. I'm confused because this doesn't happen if the players body is an rectangle. Does anybody have an idea? var game = new Phaser.Game(600, 600, Phaser.AUTO, "", {preload: preload, create: create, update: update}); var player; var cursors; var obstacles; function preload(){ game.load.image("robot", "player.png", 32, 48); game.load.image("obstacle", "box.png"); } function create(){ player = game.add.sprite(, + 200, "robot", 5); game.stage.backgroundColor = 'rgb(239, 228, 176)'; game.physics.arcade.enable(player); player.body.setCircle(player.width/2);// player don`t get seperated in the collide function //player.body.setSize(player.width * 0.8, player.height*0.8,player.width * 0.1, player.height*0.1 ); //player get seperated in the collide function player.anchor.set(0.5); player.angle = -90; cursors = game.input.keyboard.createCursorKeys(); obstacles =; game.physics.arcade.enable(obstacles); obstacles.enableBody = true; obstacles.create(, - 200, 'obstacle'); obstacles.create( - 190, - 200, 'obstacle'); obstacles.create( + 150, - 100, 'obstacle'); obstacles.create( - 130,, 'obstacle'); obstacles.create( - 230,, 'obstacle'); obstacles.setAll('body.immovable', 'true'); obstacles.setAll('anchor.x', '0.5'); obstacles.setAll('anchor.y', '0.5'); } function update(){ game.debug.body(player); obstacles.forEach(function(item) { game.debug.body(item); }); if (cursors.up.isDown) { game.physics.arcade.velocityFromAngle(player.angle, 200, player.body.velocity); } else { player.body.velocity.set(0); } if (cursors.left.isDown) { player.body.angularVelocity = -300; } else { if (cursors.right.isDown) { player.body.angularVelocity = 300; } else { player.body.angularVelocity = 0; } } game.physics.arcade.collide(player,obstacles,(p1,en)=>{ console.log(true); }, null, this); } cheers landa
  4. Phaser + Spriter - collision boxes

    Hi, Been trying to get Spriter Pro collision boxes to work in Phaser - has anyone had any luck in getting this to work? I'm close...but not quite there... This is using this plugin by the way:
  5. Hi everybody, I'm working on my first Phaser based game and so far it's really a lot of fun One thing that keeps giving me some headaches from time to time though is that P2 physics is mostly incompatible with arcade and many tutorials only work with arcade. That seems to start with the sprite bitmaps where everything is rotated 90 degrees Usually I find some workarounds or I've replaced stuff completely like the Weapon plugin, but now I'm facing an issue with collisions where I'm not quite sure what's the best solution: Let's assume we have 2 player sprites and 2 enemy sprites and each of them has some bullets to fire. So we create 2 collision groups for the sprites and 2 for the bullets: var playerCG = game.physics.p2.createCollisionGroup(); var enemyCG = game.physics.p2.createCollisionGroup(); var playerBulletsCG = game.physics.p2.createCollisionGroup(); var enemyBulletsCG = game.physics.p2.createCollisionGroup(); player1.body.setCollisionGroup(playerCG); player1.body.collides([enemyCG, enemyBulletsCG]); p1Bullets.body.setCollisionGroup(playerBulletsCG); p1Bullets.body.collides([enemyCG]); player2.body.setCollisionGroup(playerCG); player2.body.collides([enemyCG, enemyBulletsCG]); p2Bullets.body.setCollisionGroup(playerBulletsCG); p2Bullets.body.collides([enemyCG]); enemy1.body.setCollisionGroup(enemyCG); enemy1.body.collides([playerCG, playerBulletsCG]); e1Bullets.body.setCollisionGroup(enemyBulletsCG); e1Bullets.body.collides([playerCG]); enemy2.body.setCollisionGroup(enemyCG); enemy2.body.collides([playerCG, playerBulletsCG]); e2Bullets.body.setCollisionGroup(enemyBulletsCG); e2Bullets.body.collides([playerCG]); So far so good, that works fine. But now we want to change the play-mode and want to activate "friendly fire" and "friendly collisions". If we add the playerBulletsCG to player1.body.collides(...) and playerCG to p1Bullets.body.collides(...) we get a problem when the bullets are fired from withing the collision box of a player because the players own bullets collide now with his sprite :-( Obviously we could create additional groups like player1CG, player2CG and player1BulletsCG, player2BulletsCG, but then we also have to add all these groups to the enemies and we need to come up with a whole new structure of initializing all these groups in case we want to support 4 players or more. So I was wondering if there is any method that says "collide with anything but your own bullets"? I'm open for any suggestions :-)
  6. Pretty straightforward question: I want to draw my collision layers in Tiled, preferrably using the Polyline tool. I would use createFromObjects, but I don't really need the polyline to appear as a sprite, or appear at all (except for debug mode as a collision layer). Phaser: 2.6.2 Physics: Arcade Create() { ... map = game.add.tilemap('mario'); map.addTilesetImage('tileset', 'tiles'); layer = map.createLayer('Tile Layer 1'); boundary = map.objects.boundaries[0]; player = game.add.sprite(map.objects.mainPlayer[0].x, map.objects.mainPlayer[0].y, 'dude'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; ... } Update() { ... game.physics.arcade.collide(player, boundary); ...
  7. Hy there! I used a heightmap displacement on the sphere, i turned the scene collision on and checked collision for the displaced mesh but the camera doesn't collide with it. thinking maybe it has something to do with the bounding box, here's a pg:
  8. Hi I'm new to phaser and have been trying to use some of the examples as a starting point. I'm planning on using the "Pick Up Object" example, but restrict the area that the tetris shapes are placed in - so that they land on a solid platform. I would then add 3 x buttons to add more of the shapes onto the screen. Example here: Would the best way to achieve this be to build the solid platform using a kinematic sprite as documented here: If not, what is the best way define the area that the shapes are placed in - so they do not fall behind or in front of the platform and buttons? Thanks! Tom
  9. Tiled/Sprite collision

    Hi, I want to ask how to collide sprite with a tile in layer on map created in tiled. So far I have this, but it doesnt work /* global demo, game, Phaser */ demo.stateMaze = function(){}; var ball; var playerSpeed = 3; var map; demo.stateMaze.prototype = { preload: function() { game.load.tilemap('map-maze', 'assets/maps/hole_in_a_park/maze/mapa.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tileset-maze', 'assets/maps/hole_in_a_park/maze/tileset.jpg'); game.load.image('ball','assets/imgs/gula.png'); }, create: function() { game.stage.backgroundColor = '#FFFFFF'; //Starting physics game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('map-maze'); map.addTilesetImage('tileset','tileset-maze'); //CallBACK map.setTileIndexCallback(15, this.collisionHandler(), this); normal = map.createLayer('normal'); normal.resizeWorld(); wall = map.createLayer("wall"); wall.resizeWorld(); normal.renderSettings.enableScrollDelta = true; wall.renderSettings.enableScrollDelta = true; ball = game.add.sprite(0, 80, 'ball'); ball.anchor.setTo(0.5, 0.5); //Enabling ball physics game.physics.enable(ball); game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; game.input.onDown.add(function(){ if (game.scale.isFullScreen) { game.scale.stopFullScreen(); } else { game.scale.startFullScreen(false); } }); }, update: function() { //Collide game.physics.arcade.collide(ball, wall); if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ball.scale.setTo(1, 1); ball.x += playerSpeed; } if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ball.scale.setTo(-1, 1); ball.x -= playerSpeed; } if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ball.y -= playerSpeed; } if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ball.y += playerSpeed; } }, collisionHandler: function() { console.log("COLLISION!!!"); } }; But it never write COLLISION!!! so can anyone tell me what to do ?
  10. Hi There, I am having this issue with phaser(2.9.4) where collision with a tilemap only work with the base layer. In my example I have the collide-able world and then I wanted to add a background underneath that was part of the tilemap. Here is my code(excluding boot and preload) Game.preload = function () { game.stage.backgroundColor = "000000"; }; Game.create = function () { Game.scale = 5; game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 850; Game.cursors = game.input.keyboard.createCursorKeys(); = game.add.tilemap('map');'tiles_1', 'tiles'); Game.back ='Background'); Game.back.setScale(Game.scale); Game.back.renderSettings.enableScrollDelta = false; Game.spawn ='Spawn'); Game.spawn.setScale(Game.scale); Game.spawn.renderSettings.enableScrollDelta = false; Game.decor ='Decor'); Game.decor.setScale(Game.scale); Game.decor.renderSettings.enableScrollDelta = false; Game.layer ='Collideable'); Game.layer.setScale(Game.scale); Game.layer.renderSettings.enableScrollDelta = false; Game.layer.resizeWorld();[]); Game.player = game.add.sprite(,, 'player'); Game.player.scale.setTo(Game.scale); //Game.player.anchor.setTo(0.5); game.physics.enable(Game.player, Phaser.Physics.ARCADE); Game.player.body.collideWorldBounds = true;; var enemyPos = Game.findTiles(952, true); Game.enemies =; for (var enemies in enemyPos) { var enemy = game.add.sprite(enemyPos[enemies][0] * Game.scale * 16, enemyPos[enemies][1] * Game.scale * 16, 'enemy'); Game.enemies.add(enemy); enemy.scale.setTo(randomInt(1, 5)); game.physics.enable(enemy, Phaser.Physics.ARCADE); enemy.body.collideWorldBounds = true; enemy.speed = randomInt(150, 250); enemy.interval = 0; enemy.update = function () { this.interval++; if (this.interval >= 20) { this.interval = 0; if (this.x > Game.player.x) { this.body.velocity.x = -this.speed; } else if (this.x < Game.player.x) { this.body.velocity.x = this.speed; } if (this.y > Game.player.y && this.body.blocked.down) { this.body.velocity.y = -600; } } } } }; Game.update = function () { game.physics.arcade.collide(Game.player, Game.layer); //game.physics.arcade.collide(Game.player, Game.enemies); game.physics.arcade.collide(Game.enemies, Game.layer); //game.physics.arcade.collide(Game.enemies, Game.enemies); Game.player.body.velocity.setMagnitude(Math.min(1000, Game.player.body.velocity.getMagnitude())); if (Game.cursors.left.isDown) { Game.player.body.velocity.x = -500; } else if (Game.cursors.right.isDown) { Game.player.body.velocity.x = 500; } else { Game.player.body.velocity.x = 0; } if (Game.cursors.up.isDown && Game.player.body.blocked.down) { Game.player.body.velocity.y = -600; } else if (Game.cursors.up.isDown && Game.player.body.touching.down) { Game.player.body.velocity.y = -600; } }; Game.findTiles = function (id, destroy) { var mapArray = Game.spawn.getTiles(0, 0,,; var found = []; var needToFindID = id; for (var blocks in mapArray) { if (needToFindID == mapArray[blocks].index) { found.push([mapArray[blocks].x, mapArray[blocks].y]); if (destroy) {[blocks].x, mapArray[blocks].y, Game.spawn).destroy(); } } } return found; }; function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } Any help would be greatly appreciated.
  11. Hello everyone, Do you know if it is possible to add a custom collision handler for world bound collisions with the arcade physics system? I know that the onWorldBounds signal exists, but from what I've tried it seems to be fired at the beginning of the collision and it does not prevent the velocity changes from being made further down the road. Am I missing something? For clarification what I am trying to achieve is to add random direction displacement to the velocity of a ball each time it collides with the world bounds. Thank you for time.
  12. I have a function which detects collision but when the player is moving too fast or if it is too small or both, the player clips through the wall. If i can have help on how to improve/change/redo the code to make it work at higher speeds and when the player is smaller function checkPos(obj1,obj2){ if (obj1.x < obj2.x + obj2.width && obj1.x + obj1.width > obj2.x && //COLLISION FROM BOTTOM obj1.y < obj2.y + obj2.height && obj1.y + obj1.height > obj2.y) { if (obj1.x > obj2.x+obj2.width-(player.speed*2) && obj1.y + obj1.height > obj2.y+player.speed*2 && obj1.y+player.speed*2 < obj2.y + obj2.height) { // hit a block on the right obj1.x = obj1.x + player.speed } if (obj1.x+obj1.width-(player.speed+4) < obj2.x) { // hit a block on the left obj1.x = obj1.x - player.speed } if (obj1.y > obj2.y+obj2.height-(player.speed*2) && obj1.x + obj1.width > obj2.x + player.speed*2 && obj1.x+player.speed*2 < obj2.x + obj2.width){ // hit a block on the bottom obj1.y = obj1.y + player.speed } if (obj1.y+obj1.height-(player.speed*2) < obj2.y){ // hit a block on the top obj1.y = obj1.y - player.speed } } }
  13. SceneLoader

    Greetings all, I am have been a 'C' and Assembler systems coder for over 35 years. I am retired now and I want to try my hand at writing a game. I have been reading the documentation a great deal as well as looking at many examples. I have also been in communication with Dad72 who is a member here. He has been very kind. That being said I have some questions regarding the mechanics of Babylon.js. I am a real noob when it comes to this framework as I have always programmed 'on the wire' and never used a scripted language that is not strictly type cast so please forgive my ignorance. My goal is to build a 3D game that has a detective who runs around and solves crimes. He will go into several areas looking for clues and then use those clues to solve the crime. As an example, the detective may be sent to a warehouse where he will open a safe after finding the combination and then see some clues that will lead him to a suspects home. There will be human models, as well as different things that can be picked up examined and used. The story may be outside sometimes as well as inside. This is a very basic description of the mechanics of the game but I think you can see where I am going. I need some advice on what documentation I should read. What forums I should frequent and perhaps even some examples. I am really at a loss as my area is low level operating system programming in Windows, Linux, and DOS. I do have some questions about what I think may help me, so if you would not mind I would like to ask them. I have been doing some reading and stumbled upon SceneLoader.Append. Is it possible to build an entire level in Blender, then export that with the Babylon.js Blender exporter, then load that with SceneLoader.Append? Is that the best way to build the game I described. After a level is loaded can I then set up collision detection with actions? Can I bring in different models with their textures and place them in the scene after it is loaded? As an example, opening a container will expose a model that was not there before. Can I also delete models from the scene after some action. I have no idea how to accomplish any of this. I cannot load a terrain and place a model on it and keep it from falling through the terrain. I can't even build walls for a room and set up collision detection within the room. The one thing I do have is lots of time as I am retired and a clear understanding of programming principles. Thank you so much for your time, it is greatly appreciated. Regards, Richard
  14. Collision mask in Phaser

    hi guys, Why there is no collision mask (like in construct 2d) in phaser.I think that will be a good feature.
  15. On colliding with a box the camera sees through the box. In the following PGs I have used camera.ellipsoidOffset to place the camera at the middle of the ellipsoid (line 86) and used two viewposts. The lower viewport uses a second camera slightly above and behind the main camera. I have added a cone to represent the main camera with an ellipsoid around it. I have also customized the key input behaviour. Up and down arrow keys move the camera forward and backward , left and right arrow keys turn the camera. I have also lowered the speed of the camera. Face a box and walk towards it until it collides and will not move forward. You can see through the box. There is also another mystery as the camera moves forward it rises upward as can be seen by the spheres parent to the main camera. At the start you can only see the top of the sphere then as it moves the whole of the sphere becomes visible. You can see the changes in y in the console. Perhaps they are to do with my customised input manager but no - I removed it and did a PG with default behaviour same problem TLDR; These issues came to light as I am in the middle of writing a PBT (playground based tutorial) for camera collisions, gravity and customized camera inputs and have been following this thread with interest. Last week I never noticed the gravity issue or the see through the box issue. Now whether changes instigated as a result of this thread has altered some property of the camera or I am mis-remembering what I saw a week ago or was just too focused on the code for the PBT I am not sure but the mystery is there now.
  16. Hi there, I'm playing around with the v3 API and wondered how to collide with a layer of a tilemap. Here is what I've already tried: 1) Get tiles data (there is probably a better way / API helper for that like forEachTile) and then use setCollision. let tilesData = (, true, false, this.platformLayer) 2) Do the opposite by excluding an empty array.[], true, false, this.platformLayer) 3) API v2 style. this.physics.arcade.collide(this.player, this.platformLayer); Here is my game config, if someone have the time to spot what I'm doing wrong. Thanks! let config = { type: Phaser.AUTO, parent: 'content', width: 800, height: 600, pixelArt: true, backgroundColor: '#2d2d2d', physics: { default: 'impact', impact: { setBounds: true, debug: true }, }, scene: [ Boot, Preload, TileMapTest ] } let game = new Phaser.Game(config) And here is my Scene /* globals __DEV__ */ class TileMapTest extends Phaser.Scene { constructor () { super({ key: 'TileMapTest' }) if (__DEV__) { console.log('TileMapTest scene created.') } = null this.player = null this.cursors = null this.rockLayer = null this.waterLayer = null this.platformLayer = null this.stuffLayer = null } preload () { // Hero this.load.image('hero', './assets/sprites/hero.png') // Tilemap this.load.image('kenny_platformer_64x64', './assets/tilemaps/tiles/kenny_platformer_64x64.png') this.load.tilemapJSON('multiple-layers-map', './assets/tilemaps/maps/multiple-layers.json') } create () { if (__DEV__) { console.log('TileMapTest scene entered.') } this.createTileMapLayers() this.createPlayer() this.cameras.main.startFollow(this.player) this.cameras.main.setBounds(0, 0,,, 0,, // ---> @todo collide with platformLayer } update (time, delta) { this.updatePlayer(time, delta) } createPlayer () { this.player = this.physics.add.sprite(200, 200, 'hero', 4).setOrigin(0, 0.15) this.player.setActive() this.player.setMaxVelocity(500) this.player.setFriction(1000, 100) this.player.body.accelGround = 1200 this.player.body.accelAir = 600 this.player.body.jumpSpeed = 500 // this.player.body.collideWorldBounds = true this.cursors = this.input.keyboard.createCursorKeys() } createTileMapLayers () { = this.make.tilemap({ key: 'multiple-layers-map' }) let tiles ='kenny_platformer_64x64') this.rockLayer ='Rock Layer', tiles, 0, 0) this.waterLayer ='Water Layer', tiles, 0, 0) this.platformLayer ='Platform Layer', tiles, 0, 0) this.stuffLayer ='Stuff Layer', tiles, 0, 0) } updatePlayer (time, delta) { let accel = this.player.body.standing ? this.player.body.accelGround : this.player.body.accelAir if (this.cursors.left.isDown) { this.player.setAccelerationX(-accel) } else if (this.cursors.right.isDown) { this.player.setAccelerationX(accel) } else { this.player.setAccelerationX(0) } // Jump if (this.cursors.up.isDown && this.player.body.standing) { this.player.setVelocityY(-this.player.body.jumpSpeed) } } } export default TileMapTest
  17. Collision Tile Layer

    Hey guys, please help with my collision problem. thks for the help! gameState.js load.js
  18. How to use collision in phaser

    I've been trying to get my collision to work in phaser, I created my map in tiled so as far as i know i'm you use something like this "map.setCollisionBetween(264, 265, true, 'foreground');" I got the coordinates by calculating the id's from the tiles from the png file that i used in tiled. It creates the collision but not where i want it. I will insert the png file i used. so the tiled id goes like from the top left and right being 264 and 265. The bottom left and right is 297 and 298 the collision is working like this: My script looks like this: Any ideas why this is happening or how i can fix it? Thanks
  19. So a gotcha of the moveWithCollisions method is that it uses an ellipsoid mesh to calculate collisions of your mesh instead of the original mesh dimensions. I see a clear way to remove your original mesh but how do we remove the ellipsoid mesh from the scene? I'm worried that keeping these ellipsoids even when my original mesh has been disposed of will hurt performance. Thank you so much.
  20. Random Located Sprite Collision

    Hi everyone, I am trying to add collision to sprites that are randomly spawned in the map of the game. // New object of class Player the sprite name is 'ship' player = new Player("keyboardMouse",,, 200, 200, "12341", game.add.sprite(,, 'ship'), //Sprite handler object Weapons.sniperWeapon.weapon, // Weapon handler object ThrustEmitters.ourEmitter.emitter // Thrust emmiter handler object ); // loop to randomly place the sprites for (var i = 0; i < 200; i++){ var asteroid_brown = game.add.sprite(,, 'asteroid'); var rock = game.add.sprite(,, 'rock'); } In theory, I would want to make something like the resources in (trees, rocks, gold etc.) You should be able to add collision so that when the player cannot just travel through them and also when shot at you would get 1 of the specific resource. Also if this can be done in a better way, how would you do it? Thanks!
  21. My sprites are often passing through polygons that they should be bouncing off of. I've tried to research this and all I could find is that the fps may be too low to always detect the collision but surely the game engine should be able to handle this? Interestingly, if I use setCircle() my colliding sprites never pass through even with much higher velocity. Why would a polygon I define behave differently than setCircle() ? Here is a demonstration: //
  22. Sprite collision

    I am currently making a game that you can check out at and I would like to add little asteroids in a fixed random location in which the player cannot go through. I have looked at the phaser examples as well as watched some videos, but I cannot get it working. What is the best way to go about this? I have linked my files so you can check them out. I would really appreciate any help. This is the code that I am using: (create.js) function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.renderer.clearBeforeRender = false; game.renderer.roundPixels = true; game.add.tileSprite(0, 0, 30000, 30000, 'space'); //game.add.tileSprite(0, 0, 1920, 1920, 'background');, 0, 30000, 30000); //Possible weapons Weapons = { sniperWeapon: new Weapon("Sniper weapon", 0, 1000, 0, null, null, false, 5000, 90, game.add.weapon(5, 'long-bullet')), uziWeapon: new Weapon("Uzi", 20, 50, 0, null, null, false, 1500, 90, game.add.weapon(500, 'bullet')), AK47LikeWeapon: new Weapon("AK47-like", 5, 100, 0, null, null, false, 1000, 90, game.add.weapon(100, 'round-bullet')), }; ThrustEmitters = { basicEmitter: new ThrustEmitter(game.add.emitter(,, 400), ['fire1', 'fire2', 'fire3'], 0.3), ourEmitter: new ThrustEmitter(game.add.emitter(,, 1000), ['fire01', 'fire02', 'fire03'], 0.5), }; // Creating a new object of class Player player = new Player("keyboardMouse",,, 200, 200, "12341", game.add.sprite(,, 'ship'), //Sprite handler object Weapons.sniperWeapon.weapon, // Weapon handler object ThrustEmitters.ourEmitter.emitter // Thrust emmiter handler object ); game.physics.enable(player.sprite, Phaser.Physics.ARCADE); player.spawn();; player.sprite.maxVelocity = player.maxVelocity; // Game input cursors = game.input.keyboard.createCursorKeys(); var style = { font: "bold 32px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }; var text = game.add.text( - 500, - 300, "Move with W,S and mouse. \n Switch to touch/click movement with TAB. \nToggle debug with SPACE. \nShoot with LMB. \ \nSwitch weapons with 1, 2, 3.", style); text.setShadow(3, 3, 'rgba(0,0,0,0.5)', 2); //Make resources group //var resources =; //Run the show_resources function located in main.js for (var i = 0; i < 250; i++){ var asteroid_brown = game.add.sprite(,, 'asteroid'); var rock = game.add.sprite(,, 'rock'); } game.physics.enable(asteroid_brown, Phaser.Physics.ARCADE); game.physics.enable(rock, Phaser.Physics.ARCADE); // We'll set the bounds to be from x0, y100 and be 800px wide by 100px high text.setTextBounds(0, 100, 800, 100); // this.spaceButton = this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR); // this.WButton = this.input.keyboard.addKey(Phaser.KeyCode.W); // this.SButton = this.input.keyboard.addKey(Phaser.KeyCode.S); // this.AButton = this.input.keyboard.addKey(Phaser.KeyCode.A); // this.DButton = this.input.keyboard.addKey(Phaser.KeyCode.D); // this.oneButton = this.input.keyboard.addKey(Phaser.KeyCode.ONE); // this.twoButton = this.input.keyboard.addKey(Phaser.KeyCode.TWO); Keys = { space: this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR), w: this.input.keyboard.addKey(Phaser.KeyCode.W), s: this.input.keyboard.addKey(Phaser.KeyCode.S), one: this.input.keyboard.addKey(Phaser.KeyCode.ONE), two: this.input.keyboard.addKey(Phaser.KeyCode.TWO), three: this.input.keyboard.addKey(Phaser.KeyCode.THREE), four: this.input.keyboard.addKey(Phaser.KeyCode.FOUR), five: this.input.keyboard.addKey(Phaser.KeyCode.FIVE), six: this.input.keyboard.addKey(Phaser.KeyCode.SIX), seven: this.input.keyboard.addKey(Phaser.KeyCode.SEVEN), tab: this.input.keyboard.addKey(Phaser.KeyCode.TAB), } // WEAPON CHANGING{player.setWeapon(Weapons.sniperWeapon.weapon)}, this); Keys.two.onDown.add(function(){player.setWeapon(Weapons.uziWeapon.weapon)}, this); Keys.three.onDown.add(function(){player.setWeapon(Weapons.AK47LikeWeapon.weapon)}, this); // OTHER KEYS () { showDebug = true; }, this); () { if (player.movementType == "keyboardMouse") { console.log("touchMouse") player.movementType = "touchMouse" } else { console.log("keyboardMouse") player.movementType = "keyboardMouse" } }, this); game.input.keyboard.addKeyCapture([ Phaser.Keyboard.W, Phaser.Keyboard.A, Phaser.Keyboard.S, Phaser.Keyboard.D, Phaser.Keyboard.SPACEBAR, Phaser.Keyboard.ONE, Phaser.Keyboard.TWO, Phaser.Keyboard.THREE, Phaser.Keyboard.FOUR, Phaser.Keyboard.FIVE, Phaser.Keyboard.TAB, ]); } update.js: function update() { player.sprite.rotation = game.physics.arcade.angleToPointer(player.sprite); if (player.movementType == "keyboardMouse") { if (Keys.w.isDown) { game.physics.arcade.accelerationFromRotation(player.sprite.rotation, player.positiveAcceleration, player.sprite.body.acceleration); // this.isEmmiter=true; this.txtW2 = "Is W still down? YES"; if (!this.isThrustEmitter) { player.emitter.start(false, 3000, 5); this.isThrustEmitter = true; } } else if (Keys.s.isDown) { game.physics.arcade.accelerationFromRotation(player.sprite.rotation, (-1) * player.negativeAcceleration, player.sprite.body.acceleration); this.txtS2 = "S still down? YES" this.isThrustEmitter = false; } else { player.sprite.body.acceleration.set(0); this.txtW2 = "Is W still down? NO"; this.txtS2 = "S still down? YES" this.isThrustEmitter = false; } } // if (this.WButton.downDuration(250)) // { // this.txtW = "W was pressed 250 ms ago? YES"; // } // else // { // this.txtW = "W was pressed 250 ms ago? NO"; // } // if (this.SButton.downDuration(250)) // { // this.txtS = "S was pressed 250 ms ago? YES"; // } // else // { // this.txtS = "S was pressed 250 ms ago? NO"; // } if (game.input.activePointer.isDown) {; if (player.movementType == "touchMouse") { game.physics.arcade.accelerationFromRotation(player.sprite.rotation, player.positiveAcceleration, player.sprite.body.acceleration); if (!this.isThrustEmitter) { player.emitter.start(false, 3000, 5); this.isThrustEmitter = true; } } } else { if (player.movementType == "touchMouse") { this.isThrustEmitter = false; player.sprite.body.acceleration.set(0); } } //THRUST EMITTER if(this.isThrustEmitter) { //player.emitter.on = true; } else { player.emitter.on = false; } // We have to calculate the vector for thrust emitter var px = Math.cos(player.sprite.rotation) * 1000; var py = Math.sin(player.sprite.rotation) * 1000; px *= -1; //So it goes from the 'back' of the ship py *= -1; //So it goes from the 'back' of the ship player.emitter.minParticleSpeed.set(px / 2, py / 2); player.emitter.maxParticleSpeed.set(px, py); player.emitter.emitX = player.sprite.x; player.emitter.emitY = player.sprite.y; // bullets.forEachExists(screenWrap, this); } I would like the player ('ship' sprite) to not go through the asteroids ('asteroid_brown' and 'rock' sprites) but whenever I try to add physics to them or try to change them the game stops working. Thanks in advance, Fede
  23. Demo sourecode

    Hello evryone, i try to better understand collisions & mehs interactions. I found this demo on the babylon.js 101 docs:,_mesh_collisions_and_gravity Is it possible to get the source code ?
  24. Hi, I realize this is a topic that was covered before but I couldn't find a solution and wasn't sure if there was one now. I have several imported meshes in a scene (relatively complex ones) and I can drag and drop one at a time. I want to check whether the mesh I am dragging has collided with a different one. In that case it is blocked and can't be dragged further. The problem is I would like to check this precisely, meaning exactly when two meshes touch each other, and not just by using a bounding box. Is there any way to do this? Thanks for your help!
  25. Hello, i played with the car demo on playground. But im not able to apply collisions to the car. Can anyone tell what i do wrong ? Playground I added: scene.collisionsEnabled = true; // Line 6 carBody.checkCollisions = true; // Line 104 // Also to the wheels wheelFI.checkCollisions = true; // Line 96 wheelRO.checkCollisions = true; // Line 92 wheelRI.checkCollisions = true; // Line 87 wheelFO.checkCollisions = true; // Line 82 // Cubes on ground boxes.checkCollisions = true; // Line 138 But dosnt work, i dont know why.