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