Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Keeping a vehicle on the ground.

  1. #1

    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. #2
    is this problem solved?

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012