Search the Community
Showing results for tags 'phaser p2 TopDownVehicle'.
-
I've been trying to set up a top-down car game for days now. I just couldn't create car-like behaviour by myself. Then I found the TopDownVehicle class in p2's change log for version 0.7.0. The class does not seem to be implemented well in Phaser however. All over the internet I haven't found a single example case or even a mention of the class being used within Phaser. Looking at the example code found here, I came up with the following first attempt: var car = game.add.sprite(x, y, sprite, 0); // Create the vehiclevar vehicle = new TopDownVehicle(car.body);// Add one front wheel and one back wheel - we don't actually need four :)var frontWheel = vehicle.addWheel({ localPosition: [0, 0.5] // front});frontWheel.setSideFriction(4);// Back wheelvar backWheel = vehicle.addWheel({ localPosition: [0, -0.5] // back});backWheel.setSideFriction(3); // Less side friction on back wheel makes it easier to driftvehicle.addToWorld(game.physics.p2.world); // Steer value zero means straight forward. Positive is left and negative right.frontWheel.steerValue = Math.PI / 16; // Engine force forwardbackWheel.engineForce = 10;backWheel.setBrakeForce(0);Then, when I try to update the vehicle, in order to see the results, I get the following error: vehicle.chassisBody.vectorToWorldFrame is not a function(..)The error makes sense, since the vectorToWorldFrame function is located in vehicle.chassisBody.data.vectorToWorldFrame instead. I think proper implementation of this class in Phaser could help a lot of novice game designers out. Or am I missing something in the Phaser documentation? Any leads on how to best approach this?