I started creating a 2D pop-down racing game with chipmunk as physics engine.
The gravity is set to (0,0) and damping is used to create the friction between the cars and the ground .The cars are accelerated by adding velocity to their bodies.
I would like to accelerate heavy vehicles slower than light ones, but the damping is not influenced by the weight.
Another problem is that the process of accelerating to the max-speed is very short. The maximum speed is reached after less than a second.
I am trying to solve this problem for days now and i have no solution.
My code for the cars:
Code: Select all
for (int i = 0;i<=ncars;i++){ // 0-ncars
//NSLog(@"car nr.: %i", i);
//steering:
float angvel;
angvel=cpBodyGetAngVel(car[i].shape->body);
angvel*=0.1;
angvel-=car[i].lenkung*dt*30;
cpBodySetAngVel(car[i].shape->body, angvel);
car[i].speed=pow(((car[i].node.position.x-car[i].lastx)*(car[i].node.position.x-car[i].lastx))
+((car[i].node.position.y-car[i].lasty)*(car[i].node.position.y-car[i].lasty)) , 0.5 );
//cpBodyApplyImpulse(car[i].shape->body,
// cpv(30000000*sin(CC_DEGREES_TO_RADIANS(car[i].node.rotation)), 30000000*cos(CC_DEGREES_TO_RADIANS(car[i].node.rotation))),
// cpv(0,0));
cpVect carvel = cpBodyGetVel(car[i].shape->body);
//drifting:
carvel.x=0.9*(carvel.x*abs(sin(CC_DEGREES_TO_RADIANS(car[i].node.rotation))))+0.1*(carvel.x);
carvel.y=0.9*(carvel.y*abs(cos(CC_DEGREES_TO_RADIANS(car[i].node.rotation))))+0.1*(carvel.y);
//acceleration:
carvel.x=carvel.x+ car[i].gas *20*sin(CC_DEGREES_TO_RADIANS(car[i].node.rotation));
carvel.y=carvel.y+ car[i].gas *20*cos(CC_DEGREES_TO_RADIANS(car[i].node.rotation));
//carvel.x*=dt;
//carvel.y*=dt;
cpBodySetVel(car[i].shape->body , carvel);
//NSLog(@"car[i].node.rotation: %f",car[i].node.rotation);
car[i].pic.position = ccp(car[i].node.position.x,car[i].node.position.y);
car[i].pic.rotation = car[i].node.rotation;
car[i].lastx=car[i].node.position.x;
car[i].lasty=car[i].node.position.y;
}