Sign in to follow this  
ridefast42

returning the proper collision

Recommended Posts

Hey guys. I have my physics up and running and I am doing colliison now. So far this is how I loop through my collision lines that are in the environment. This works, but since I am only checking the x coords it will not work If I create a line above another. My question is, what is the best way to check which collision line to return?
int collision::checkcollision(object& objecttocheck, int height)
{
	int inc;
	for(inc = 0;inc < allcols.size() - 1; inc ++)
	{
		if(objecttocheck.x >= allcols[inc].x1 && objecttocheck.x < allcols[inc].x2)
		{
			return inc;
		}
	}
}

Share this post


Link to post
Share on other sites
That depends on what kind of object you're trying to collide. Typically, you write a separate collision testing function for each pair of shapes (circle, rectangle, ray, convex polygon, etc).

Share this post


Link to post
Share on other sites
Well, it is all polygons, and it will loop through all the vertices of the polygons(which is not yet done) and i want it to return the the line that any of the points is "most likely" to hit. When I say most likely, that means the only line it can possibly hit giving its coordinates.

Share this post


Link to post
Share on other sites

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