Sign in to follow this  

Collide and Slide

This topic is 2845 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

Hope this is the right forum. I am trying to have the ship, once it has hit the wall of blocks, to slide along the edge of the wall with the following code. http://img175.imageshack.us/img175/525/slides.png
		object *obj = ps->tiles[i];
		float r0 = ps->tiles[i]->get_radius(),
			r1 = get_radius();
		coord temp_coord = pos + (direction*speed);
		if((temp_coord.x + r1 > obj->pos.x - r0) && (temp_coord.x - r1 < obj->pos.x + r0) &&
			(temp_coord.y + r1 > obj->pos.y - r0) && (temp_coord.y - r1 < obj->pos.y + r0)){
			if(pos.y + r1 < obj->pos.y - r0 || pos.y - r1 > obj->pos.y + r0)
				dir.y = 0;
			if(pos.x + r1 < obj->pos.x - r0 || pos.x - r1 > obj->pos.x + r0)
				dir.x = 0;

		}

It works sort of. On the 'Y' axis it'll slide up fine but when sliding down it'll bump(stop and continue, stop and continue etc), on the 'X' axis it'll do this for both directions. Any ideas why this could be happening? Thanks.

Share this post


Link to post
Share on other sites

This topic is 2845 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