I have an interesting question. How do would you go about keeping a vehicle on the ground as it moves across a bitmap?
Heres my current method, it works… However, it has it’s strange bugs… Like, when the vehicle comes to a cliff it tends to pop up into the air. Which, I am going to add yet another workaround for…
Anyone know how it’s done in flash biking games like this?
*Explanation: findGroundFine is a function that uses about 3-10 hittests to find the land edge by hit testing the bitmap. The points move closer together the higher the vehicle is rotated to keep them in place in the front and back of the wheels.
Theres a few bits of workaround code… If the vehicle is falling off a cliff, it doesn’t automatically snap into position on the land.
//Keep buggy on ground
var leftFirstWheelY = global.findGroundFine(x-(10-(Math.abs(rotation)/16)), y);
var rightFirstWheelY = global.findGroundFine(x-(5-(Math.abs(rotation)/16)), y);
var leftFirstWheelX = x-(10-(Math.abs(rotation)/16));
var rightFirstWheelX = x-(5-(Math.abs(rotation)/16));
var rightSecondWheelY = global.findGroundFine(x+(10-(Math.abs(rotation)/16)), y);
var leftSecondWheelY = global.findGroundFine(x+(5-(Math.abs(rotation)/16)), y);
var rightSecondWheelX = x+(10-(Math.abs(rotation)/16));
var leftSecondWheelX = x+(5-(Math.abs(rotation)/16));
var groundPointY = (leftFirstWheelY + rightFirstWheelY + rightSecondWheelY + leftSecondWheelY) / 4;
if (groundPointY > y && Math.abs(groundPointY - y) > 10) {
velY ++;
} else if (groundPointY < x && Math.abs(groundPointY - y) > 10) {
velY--;
} else {
velY = 0;
y = groundPointY;
var buggyRotation = rotate2Point(Math.atan2(((leftFirstWheelY + rightFirstWheelY)/2)-((rightSecondWheelY + leftSecondWheelY)/2), ((leftFirstWheelX + rightFirstWheelX)/2)-((rightSecondWheelX + leftSecondWheelX)/2)));
rotation = buggyRotation+180;
}