• Content Count

  • Joined

  • Last visited

  1. Yes I saw it and actually used some parts as a starting point. Answering your question, I wanna use P2 because it gives a better body handling - it actually turns it, when arcade physics just pretend to turn the actual physical body of a tank (it turns an image, but if you use debug you'll see what i'm talking about). And the reason for that is that my tanks are not perfect square shapes, they are rectangles. Moreover, I have a plan to use PhysicsEditor to shape some of the tanks and give them some angles. So that's why I'm not using arcade.
  2. The best example I've found of what I'm trying to achieve is this - However, instead of a car I have a tank, so the movement should be more... tankish, without this front-wheels-turning effect. But this is not a problem. The problem is that my tank's movement looks more like a boat on a water movement. I press UP for acceleration and when I press LEFT or RIGHT it still moves in the same direction for a while, like drifting. And if I release UP button and press LEFT or RIGHT again it drifts as well, without taking into account, that he has turned 90 degrees already. Looks awful in terms of a tank behaviour. In other words, I want my tank to stay "on track" while turning, without such huge drift (or asteroid in space) effect. I suppose this is something I should do in update section. Here is what I have there for now: if (cursors.left.isDown) {tank.body.angularVelocity = -0.75;} else if (cursors.right.isDown) {tank.body.angularVelocity = 0.75;} else {tank.body.setZeroRotation();} if (cursors.up.isDown) {tank.body.thrust(120);} else if (cursors.down.isDown) {tank.body.reverse(70);} else {tank.body.damping = 0.8;}cursors = game.input.keyboard.createCursorKeys(); And a few more, not related to main topic, questions: What kind of P2 library Phaser is using? Is it the same as in the example I've provided in the beginning? Is it technically possible in Phaser to calculate collision angle between shell and an object, e.g. another tank? Thank you.
  3. jmp909, at first your solution didn't work, but I've managed to figure it out and adapt for my game. I didn't understand, why you use tankBase instead of just tank. Anyway, after changing it to tank everywhere - it started to work. But there is one more issue coming out of your code. In my situation bullets... well it would be more correct to call them shells... So shells are coming out of the wrong place, looks like it is positioned not in the turret's center. Here are some pictures for better understanding, the red dot is an approximate point where the shells are coming from: I understand that it is something with fire () function, but I'm too stupid to understand what exactly is causing this
  4. jmp909, thanks a lot! I'll check it out and reply.
  5. I'm a newbie in Phaser and programming as well, so I apologize if this question is stupid. I took this tanks example as a base code. This example is great, while the turret is in the middle of the hull, but in my case it is slightly moved to the front of the tank: If i use the code without changes, when tank turns, his turret is not positioning correctly anymore: So, I googled a bit and found addchild solution: tank.addChild(turret); turret.x = 11; turret.y = 0; Now it looks great, turret stays on its correct position at any circumstances: BUT, STOP! What is this??? Turret's anchor (or rotation point) is positioning in a wrong place, it does not move with tank and stays in the same place of the "map". Moreover, bullets fire from the same position and do not move with tank as well: And it will stay there, no matter what happens. The situation is changing if I add: turret.x = tank.x; turret.y = tank.y;to update() section. Now anchor and bullets are in the right place and moving with tank. But turret is trolling me again: As its coordinates are updating, it runs ahead all the time. This thing is driving me crazy for at least past 3 hours and I have a feeling, that I'm missing something very simple. Full code (sorry, didn't find how to put it in hide): var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });function preload () { game.load.image('bullet', 'asset/shell.png'); game.load.image('tank', 'asset/games/tanks/tank1.png'); game.load.image('turret', 'asset/games/tanks/turret.png'); game.load.image('earth', 'asset/games/tanks/scorched_earth.png'); game.load.spritesheet('kaboom', 'asset/games/tanks/explosion.png', 64, 64, 23); }this.bullets = bullets;this.fireRate = 1000;var land;var tank;var turret;var explosions;var currentSpeed = 0;var cursors;var bullets;var fireRate = 1000;var nextFire = 0;function create () { // Resize our game world to be a 2000 x 2000 square, -1000, 2000, 2000); // Our tiled scrolling background land = game.add.tileSprite(0, 0, 800, 600, 'earth'); land.fixedToCamera = true; // Our bullet group bullets =; bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.createMultiple(30, 'bullet', 0, false); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true); // The base of our tank tank = game.add.sprite(0, 0, 'tank', 'tank1'); tank.anchor.setTo(0.5, 0.5); tank.animations.add('move', ['tank1'], 20, true); // This will force it to decelerate and limit its speed game.physics.enable(tank, Phaser.Physics.ARCADE); tank.body.drag.set(0.2); tank.body.maxVelocity.setTo(400, 400); tank.body.collideWorldBounds = true; // Finally the turret that we place on-top of the tank body turret = game.add.sprite(0, 0, 'turret', 'turret'); turret.anchor.setTo(0.15, 0.5); tank.addChild(turret); //turret.x = 11; //turret.y = 0; // Explosion pool explosions =; for (var i = 0; i < 10; i++) { var explosionAnimation = explosions.create(0, 0, 'kaboom', [0], false); explosionAnimation.anchor.setTo(0.5, 0.5); explosionAnimation.animations.add('kaboom'); } tank.bringToTop(); turret.bringToTop();; = new Phaser.Rectangle(150, 150, 500, 300);, 0); cursors = game.input.keyboard.createCursorKeys();}function update () { if (cursors.left.isDown) { tank.angle -= 4; } else if (cursors.right.isDown) { tank.angle += 4; } if (cursors.up.isDown) { // The speed we'll travel at currentSpeed = 300; } else { if (currentSpeed > 0) { currentSpeed -= 4; } } if (currentSpeed > 0) { game.physics.arcade.velocityFromRotation(tank.rotation, currentSpeed, tank.body.velocity); } land.tilePosition.x =; land.tilePosition.y =; turret.x = tank.x; turret.y = tank.y; turret.rotation = game.physics.arcade.angleToPointer(turret); if (game.input.activePointer.isDown) { // Boom! fire(); } }function fire () { if ( > nextFire && bullets.countDead() > 0) { nextFire = + fireRate; var bullet = bullets.getFirstExists(false); bullet.reset(turret.x, turret.y); bullet.rotation = turret.rotation; game.physics.arcade.moveToPointer(bullet, 1500); }}function bulletHitPlayer (tank, bullet) { bullet.kill();}