# bigboy

Members

5

• Rank
Newbie
1. ## P2 physics for top-down tank motion

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. ## P2 physics for top-down tank motion

The best example I've found of what I'm trying to achieve is this - http://schteppe.github.io/p2.js/demos/topDownVehicle.html 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. ## Child sprite anchor - strange behaviour

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. ## Child sprite anchor - strange behaviour

jmp909, thanks a lot! I'll check it out and reply.