detecting the color of a pixel, for colossion detect

fguihen

Well-known member
Joined
Nov 10, 2003
Messages
248
Location
Eire
i have a bot moving between red rectangles. when the bot gets near a rectangle, i want him to alter his position to avoid the red. how could i accomplish this , using c#? thanks for reading my post.
 
Are you controlling the bot with the keyboard?

You will have to draw the drawings in a bitmap, because you cannot check for red on a form (unless you use API). After the bot moves, use your bitmaps .GetPixel to check if it hits red. If it does, move it back in the opposite direction that it just moved. :)
 
no , the bot is supposed to work by itself to avoid objects . i dont think color detection is the way though. if i can find a way to make the bot start turning left or right when an object(wall or other bot) comes within my bots field of vision ( maby the width of the bot*3 in front of the bot). hope this is a little clearer
 
Ive tried Color collision detection..
What you gotta do is use the GetPixel command to get the color of your pixel and then calculate collision based on that.. my experience is, its very slow.

Hmm.. I know im stating an obvious, but youd have to develop an algorithm for what direction the bot moves in after he hits something.

View my tutorial on collision detection between square objects, it speaks about proximity algorithms and bounding boxes, perhaps you can modify that a little bit for your program:
http://www.vbprogramming.8k.com/tutorials/CollisionDetection.htm

You can modify it so that it checks for collision constantly, but youd have to develop an algorithm to tell the bot where to move after it collides - obviously going in the opposite direction, but youd want to add a bit of "Randomness" and allow for more directions (still going the other way, just not directly opposite every time)

-The Pentium Guy
 
Back
Top