Sign in to follow this  

I are to stupid, i need help!

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

If you intended to correct an error in the post then please contact us.

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][right]==0|map[down2][right]==0) { canGR = false, xInertia = 0, fixX(-10); }//going right
     else { canGR = true; }

     if(map[up2][left]==0|map[down2][left]==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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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


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

Share this post


Link to post
Share on other sites
Quote:
Original post by dustydoodoo
maybe 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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this