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.


Results 1 to 2 of 2

Thread: Uneven terrain collision detection

  1. #1

    Uneven terrain collision detection

    I making a lander style game where you fly around and save penguins (dont ask!) and then you fly your helicopter to a landing pad. There is along way to go, but the collision detection wont work and im out of ideas! Here is the problem:

    Here is the swf

    Ive used this as the basis of the hit collection, a sentry/perimeter setup. There is a perimeter set around the helicopter, and one set around the ground. If they two hit each other, then some code moves them apart. It works really well. But sometimes, the helicopter gets stuck inside the the ground (see swf). Here is the code that does the testing:

    PHP Code:
    ground_collision = function(lo) {
        
        var 
    c=0;
        var 
    xs=0;
        var 
    ys=0;
        var 
    diff=0;

        for (
    i in l.perim) {
                
            
    l.perim.localToGlobal(p={x:l.perim[i]._x,y:l.perim[i]._y})

            if(
    o.hitTest(p.xp.ytrue)){

                        
    _root.fuel -= 5;
                        
    _root.points -= 1;
                        
    xMovement *= -1;
                        
    gravity *= -1;
            }

            
            
    ys += p.y;
            
    xs += p.x;
            
    c++;
        }

    As you can see, it simply reverses the gravity and xmovement so that the helicopter goes away from the ground. If it moves slowly, this works brilliantly. However, if you hit it with any speed, the helicopter goes right through. I know why this is, I just cant fix it

    Can anyone suggest a better method?

  2. #2
    I made a platform game as a final year project at uni.. The way I did it was, calculate the ySpeed, and then:

    Code:
    groundHit=false;
    for i=Math.round(yPosition);i<=yPosition+Math.round(ySpeed);i++
    if(ground_collision(xPosition,i))
    {
    yPosition=i;
    groundHit=true;
    break;
    }
    if(!groundHit)
    yPosition=yPosition+ySpeed;

    No idea if an approach like this is applicable to flash at all? (my game was written with DirectX and C++). Another approach could be to simply stop ground collisions from happening if the sprite is heading upwards?

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