Currently, I am experimenting with Box2dWeb and creating a top-down car game.
The issue I am facing is related to controlling the car's movement. Initially, I want the car to only move forward without using wheels. Instead, I am applying force directly to the car, which is represented as a box.
I have created a function for handling controls, but for some reason, it is not being called. This is where I require some guidance or advice. (The creation and placement of objects are functioning correctly)
Below is a snippet of the code:
var GlobalVar={ }
var KEY = {
UP: 87,//W
DOWN: 83,//s
LEFT: 65,//A
RIGHT: 68//D
}
GlobalVar.pressedKeys = [];//an array to remember which key is pressed or not
$(function(){
$(document).keydown(function(e){
GlobalVar.pressedKeys[e.keyCode] = true;
});
$(document).keyup(function(e){
GlobalVar.pressedKeys[e.keyCode] = false;
});
Rendering();
PlaceStuff(GlobalVar.currentLevel);//placing stuff, like car and boundaries/walls
moveCar();
});
function moveCar(){
if (GlobalVar.pressedKeys[KEY.UP]){
var force = new b2Vec2(0, -10000000);
GlobalVar.car.ApplyForce(force, GlobalVar.car.GetWorldCenter());
}
}