Author Topic: Edge detection! IDEA!  (Read 1187 times)

rolandinho

• Member
• Posts: 39
• Karma: +0/-0
Edge detection! IDEA!
« on: Sun, Aug 1, 2010 »
Hi to everyone,

I am new to Flixel and just started learning this amazing Engine a couple of days ago.

I just started by using some sprites i found on the internet!

I've seen people here in the forum searching for a way to do edge detection and here is my idea:

I have two squares following the player and they check if the player(when he stops) stands on a edge or not - simply by checking the distance between both squares.

I hope this helps - here is a demo i made:
http://desro.de/game/floorCheck/gameTest.html

I just want to work on some ideas before i start making a own game!

zyxstand

• Member
• Posts: 94
• Karma: +0/-0
Re: Edge detection! IDEA!
« Reply #1 on: Sun, Aug 1, 2010 »
that's a very neat idea i feel, and i've never heard of it.
of course there are more "logical" (meaning programmingly efficient) ways to check for edgene.
Maybe you can do the following things to improve on it - it currently takes a whole second before entering edge animation.  i notice that the two squares start falling when your velocity is 0 - which is fine, but i think you should set the squares' y velocity to something higher (I hope you're not using acceleration on them) so that they'll essentially detect the edge faster.

i like this idea.

Jim

• Guest
Re: Edge detection! IDEA!
« Reply #2 on: Sun, Aug 1, 2010 »
Since I can't see your source I have no idea if this way is better or worse than yours, but here's how I've been doing it
Code: [Select]
`                //instance variables public var hitsprite:FlxSprite; public var collidebool:Boolean; //in contructor hitsprite = new FlxSprite(0,0).createGraphic(1,1); hitsprite.visible = false; //in update //place the hitbox if ( facing == LEFT) { velocity.x = -1*_walkspeed; hitsprite.x = x-1; hitsprite.y = y+14; } else { velocity.x = _walkspeed; hitsprite.x = x+14; hitsprite.y = y+14; } //check if it hits the map, if it doesn't you are on an edge collidebool = false; FlxU.overlap(_map,hitsprite,changedirection); if(collidebool == false) { if (facing == LEFT) { facing = RIGHT; } else { facing = LEFT; } } //change direction function public function changedirection(Object1:FlxObject,Object2:FlxObject):void { collidebool = true; }`
This is just copy pasta from one of my enemy doods who turns around when he meets an edge, but you get the idea
« Last Edit: Sun, Aug 1, 2010 by Jim »

rolandinho

• Member
• Posts: 39
• Karma: +0/-0
Re: Edge detection! IDEA!
« Reply #3 on: Sun, Aug 1, 2010 »
My code works quite the same like yours!!

Thanks for the imput guys!

zez

• Active Member
• Posts: 203
• Karma: +0/-0
Re: Edge detection! IDEA!
« Reply #4 on: Sun, Aug 1, 2010 »
depending on sprite width, theres always
Code: [Select]
`if (map.getTile(left/tilewidth, (bottom /tileheight) + 1) >= map.collideIndex && map.getTile(right/tilewidth, (bottom /tileheight) + 1 < map.collideIndex){ your left side is on an edge, do stuff}if (map.getTile(left/tilewidth, (bottom /tileheight) + 1) < map.collideIndex && map.getTile(right/tilewidth, (bottom /tileheight) + 1 >= map.collideIndex){ your right side is on an edge, do stuff}`Of course, that breaks pretty hard in the event that the sprite in question isnt wider then the tiles, but it doesnt require any extra objects or variables.