• 12
• 12
• 9
• 10
• 13

I are to stupid, i need help!

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Well, forgive me if i make any mistakes, because i havent been here since forever. I have just got back into programing, now i am using SDL. I am making a tile based game engine. I need help with the collision detection. I only know of one way to check for collisions within the array. im not sure how i am suppose to post code though... im sure there is some special way to do it. by the way its in c++
void Map::checkC(){

right = (midX+(MANW/2)+xInertia)/TILEW;
right2= (midX+(MANW/2)-1)/TILEW; // right2/left2 are for checking either side of the vertical collision detection
left  = (midX-(MANW/2)+xInertia)/TILEW;
left2 = (midX-(MANW/2)+1)/TILEW; //
up    = (midY-(MANH/2)+yInertia)/TILEH;
up2   = (midY-(MANH/2)+1)/TILEH; //
down  = (midY+(MANH/2)+yInertia)/TILEH;
down2 = (midY+(MANH/2)-1)/TILEH; // up2/down2 are for checking either side for horizontal collision detection

if(map[up2]==0|map[down2]==0) { canGR = false, xInertia = 0, fixX(-10); }//going right
else { canGR = true; }

if(map[up2]==0|map[down2]==0) { canGL = false, xInertia = 0, fixX(10); }//going left
else {canGL = true; }

if(map[up][right2]==0|map[up][left2]==0) { canGU = false, yInertia=0, fixY(10);}//going up
else { canGU = true; }

if(map[down][right2]==0|map[down][left2]==0) { canGD = false, grounded(), fixY(-10); }// going down
else { canGD = true, notGrounded();}

}
void Map::fixX(int X){ //
midX = (right*TILEW)+X;
}
void Map::fixY(int Y){ //
midY = (down*TILEH)+Y;
}


Share on other sites
the problem ive been having is that when you jump on an angle into the bottom corner of a tile, the character appears ontop of that tile. i has something to do with detecting the vertical collision. But im not sure if this is the right way to check for collisions.

Share on other sites
And if you cant help me with the code i posted, just tell me another way of detection collisions for a tile based game please. i remember reading something about using a square root function for collision, but i dont know how that would work...

Share on other sites
maybe if i knew how to use a debugger i would be able to find out whats happening

Share on other sites
I don't have time to read the source code in great detail, but when it detects a collision, it should be fairly simple to detect whether the current vertical position of the object is lower than the current vertical position of the tile, and if it is, just set the vertical position of the object such that it matches with the bottom of the tile.

I don't see any major conflict with this approach among the code you displayed, but, like I said, I just skimmed through it.

Also, please don't bump your topic after five minutes with no reply, please don't quadruple post (there's an edit button) and please post source code in (source) (/source) tags (replace the () with []). This makes it easier to read your posts and will make it more likely for you to get a response.

Finally, collision detection falls primarily under the domain of the math and physics forum, so you'd be more likely to get a helpful answer there.

Share on other sites
Quote:
 if(map[up2]==0|map[down2]==0)

Perhaps you meant to use || (logical or) rather than | (bitwise or).
Same goes for the rest of the 'if' statements.

Share on other sites
Quote:
 Original post by dustydoodoomaybe if i knew how to use a debugger i would be able to find out whats happening

A debugger is a fairly essential tool these days:

Visual C++ Debugger

Use of the Debugger in Visual C++

Basic Debugging Features In Visual Studio 2005

Most of those are links to Visual Studio based debugging since that's what most people around here, on windows at least ;) will be using.

Andy