The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

# Thread: Keeping a vehicle on the ground.

1. 103
posts
Dude...

## Keeping a vehicle on the ground.

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?
http://dirt-bike-2.freeonlinegames.com/

*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.

Code:
```                //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;
}```
Last edited by DesignerMichael; July 5th, 2008 at 02:24 AM.

2. is this problem solved?

3. 103
posts
Dude...
Nope... Thinking about using fisix or something like that... Actually, thats flex... Damn!
Last edited by DesignerMichael; July 7th, 2008 at 02:50 AM.