News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

Rounded hit collision?

Farted by F U Clock, January 24, 2011, 02:37:04 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

F U Clock

I'm thinking of making a 2D platforming game (no scrolling, screen-by-screen) that would use typical platforming controls (arrow key movement, jumping, crouching, maybe climbing ladders). In looking for good tutorials to base my code on, I've found a few I like parts of but nothing including platforms with rounded edges. Pretty much everything I've found just uses straight up and down "walls" and straight horizontal platforms. I was hoping to have angled platforms at least. Is this even possible in Flash with hit detection? Anyone know a good tutorial that has this? I've attached an image to show what I'm talking about.

PineappleClock

If i am not mistaken, I believe most engines that do this just quantize the platforms into discrete rectangular regions and do hit detection with that - you could write a script that quantitizes it into another (hidden) MC and then do hit detection with the MC.

Then you just make a vertical step threshold where the character will automatically step to the higher plaform if the difference is below a certain amount. You could average the vertical distance during this so the player can't tell that they are standing on an approximation of the surface.

Slurpee

probably not adding anything to the conversation because I've only flirted with flash programming as best but you know fancy pants adventure? it's almost nothing but what you're talking about.

F U Clock

Quote from: Slurpee;1804253probably not adding anything to the conversation because I've only flirted with flash programming as best but you know fancy pants adventure? it's almost nothing but what you're talking about.

That code is brilliant and I want it badly. Thanks for showing me this is doable... Piney I'll see if I can work with what you're suggesting. The main problem being I'm not a programmer either but I can usually sweat my way through a lot of difficult things if I have something to base them on. Sadly with this, like I said, I'm not finding a lot of tutorials or just .flas with similar coding.

PineappleClock

after looking at the code to that game, he's just using hitTest - basically advancing the character and checking hittest against a smooth representation of the level, then moving it 2px towards it until it hits, then 1px away until it clears, then doing hitTest in a loop while rotating it one way or another until it clears to do the correct rotation, but with a lot of magic numbers and such. It looks like he started with that and then worked to perfect the algorithm.

AstronautClock


F U Clock

Quote from: PineappleClock;1804278after looking at the code to that game, he's just using hitTest - basically advancing the character and checking hittest against a smooth representation of the level, then moving it 2px towards it until it hits, then 1px away until it clears, then doing hitTest in a loop while rotating it one way or another until it clears to do the correct rotation, but with a lot of magic numbers and such. It looks like he started with that and then worked to perfect the algorithm.

Hot dog that sounds complex but where did you get the code from? Can you just fetch it from the .swf?

PineappleClock

Quote from: F U Clock;1804307Hot dog that sounds complex but where did you get the code from? Can you just fetch it from the .swf?

you could, but its here:

http://swfchan.com/1/1003/info.shtml?Fancy_Pants_Adventure.swf

click actionscript, expand all then search for "RLFunc = function () {"
this is the function that lets the character walk left and right - FOR INSPIRATION ONLY I DO NOT CONDONE DIGITAL PLAGARISM

F U Clock

Thanks for all the help, Piney.

I've been working through some ghetto-ass coding and having pretty good results... Really the bare bones of the engine works, but now I'm trying to get the character's movements work well. Check out this test screen (graphics obviously are for testing purposes DON'T JUDGE ME).

http://www.mattchathamdesign.com/Side_Scroller_Test.html

Arrows to move, space to jump, hit control to run (you'll have to do this to make it onto the platform).

Hit detection all seems pretty good... The main problem I'm running into as I'm adding character animations is finding a way to detect key releases. I know Flash doesn't have a great way to do it, and I may end up having to take out the run function because I know adding two keys at once just makes shit wild. Basically if there's a good way y'all know of to detect key UP, lemme know. Here's my source code, it's basically all on the character (I apologize for it not being very clean or well-done).

onClipEvent (load) {
    gravity = 0.2;
    yspeed = 0;
    xspeed = 1;
    jumping = 0;
}
onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)){
                            this.gotoAndStop("WALKLEFT");
                            this.DIRECTION == "L"
                            }
    if (Key.isDown(Key.LEFT) and (Key.isDown(Key.CONTROL))){
                            this.gotoAndStop("RUNLEFT");
                            this.DIRECTION == "L"
                            }
        if (Key.isDown(Key.LEFT) and (_root.mcPLAYER, hitTest(_root.mcLEFTWALL1) == false)) {
            if (!_root.terrain.hitTest(_x-_width/2, _y+_height/8, true)) {
                _x -= xspeed;
            }
        }
        if (Key.isDown(Key.RIGHT)){
                            this.gotoAndStop("WALKRIGHT");
                            this.DIRECTION == "R"
                            }
        if (Key.isDown(Key.RIGHT) and (Key.isDown(Key.CONTROL))){
                            this.gotoAndStop("RUNRIGHT");
                            this.DIRECTION == "R"
                            }
        if (Key.isDown(Key.RIGHT) and (_root.mcPLAYER, hitTest(_root.mcRIGHTWALL1) == false)) {
            if (!_root.terrain.hitTest(_x+_width/2, _y+_height/8, true)) {
                _x += xspeed;
            }
        }
        if ((Key.isDown(Key.SPACE)) and (!jumping)) {
            yspeed = -5;
            jumping = 1;
        }
        if ((Key.isDown(Key.CONTROL)) and (!jumping)) {
            xspeed = 2;
        }
        yspeed += gravity;
        while (_root.terrain.hitTest(_x, _y+_height/2, true)) {
            _y--;
            yspeed = 0;
            jumping = 0;
        }
           
        if ((!_root.terrain.hitTest(_x, _y+_height/2+1, true)) or (yspeed<0)) {
            _y += yspeed;
        } else {
            yspeed = 0;
            jumping = 0;
        }
    }
   
        onClipEvent (enterFrame) {
    if (_root.mcPLAYER, hitTest(_root.mcCEILING1)) {
            yspeed = +5;
        }
    }