# Keeping a vehicle on the ground

**URL:** <https://forum.kirupa.com/t/keeping-a-vehicle-on-the-ground/265168>\
**Category:** Uncategorized\
**Created:** [July 5, 2008, 6:18am UTC](https://forum.kirupa.com/t/keeping-a-vehicle-on-the-ground/265168 "2008-07-05T06:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DesignerMichael](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@DesignerMichael](https://forum.kirupa.com/u/DesignerMichael)\
**Post date:** [July 5, 2008, 6:18am UTC](https://forum.kirupa.com/t/keeping-a-vehicle-on-the-ground/265168/1 "2008-07-05T06:18:45Z")

</div>

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?

> **[Dirt Bike 2](http://www.freeonlinegames.com/game/dirt-bike-2)**
>
> Dirt Bike 2 will test your biking skills in one of the most dangerous rocky terrains around. Some obstacles you can jump over whilst others require you to ride the bike slowly. The bike is very agile and can easy crash or topple over. A timline at...

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

```auto

                //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;
                }

```

---

<div class="post-metadata">

**Author:** ![acebuddy29](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@acebuddy29](https://forum.kirupa.com/u/acebuddy29)\
**Post date:** [July 7, 2008, 6:23am UTC](https://forum.kirupa.com/t/keeping-a-vehicle-on-the-ground/265168/2 "2008-07-07T06:23:39Z")

</div>

is this problem solved?

---

<div class="post-metadata">

**Author:** ![DesignerMichael](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@DesignerMichael](https://forum.kirupa.com/u/DesignerMichael)\
**Post date:** [July 7, 2008, 6:35am UTC](https://forum.kirupa.com/t/keeping-a-vehicle-on-the-ground/265168/3 "2008-07-07T06:35:01Z")

</div>

Nope… Thinking about using fisix or something like that… Actually, thats flex… ■■■■!
