Page 1 of 1

Help! My math apparently sucks (Line Query)

Posted: Thu Aug 04, 2011 12:17 pm
by mster50
Hello all,

If anyone could assist with an issue, I'd be very grateful.

I'm having trouble figuring out the proper location of the outer edge of a shape using a line query. I'm querying the space from the location of let's say, the player's shape, to a touch point (which is another shape), and was using the first point touched as the location to attach a sliding joint that connects to the player.

The problem I am facing is the intersecting point is not always the proper point in relation to the touch location, and I'm having trouble figuring out how to account for that. Hopefully this picture helps.

Image

Thank you very much for any advice.

Re: Help! My math apparently sucks (Line Query)

Posted: Thu Aug 04, 2011 1:16 pm
by slembcke
Unfortunately it's nearly that simple if multiple shapes are involved. Your purple location might be inside of another shape that the raycast didn't even hit.

What you really want is to find the closes point on the polygon to the touch point, but you'll have to calculate that yourself as Chipmunk doesn't have any functions to do that. I'm not sure how you can merge that with the raycasting into anything meaningful though.

Other than that the best you can really do is to take the ray intersection point and move away from the surface along the normal by the shape's radius. p + n*r where p is the intersection point, n is the normal, and r is the player radius. That too might end up inside a second shape, but it's about the

Re: Help! My math apparently sucks (Line Query)

Posted: Thu Aug 04, 2011 4:19 pm
by mster50
Ah, yes, excellent. Thank you for the suggestion there. I had considered doing something like that, but was unsure of how to, really.

Is the radius of a shape available using a shape query? That would be awesomely helpful if so. I may have missed it, so I apologize if that's a retarded question.

Re: Help! My math apparently sucks (Line Query)

Posted: Thu Aug 04, 2011 4:59 pm
by slembcke
If it's a circle shape then you can do cpCircleShapeGetRadius().

Re: Help! My math apparently sucks (Line Query)

Posted: Thu Aug 04, 2011 5:19 pm
by mster50
Ah yes, excellent. I think I can fix this up then, thanks Scott. You're awesome.

Re: Help! My math apparently sucks (Line Query)

Posted: Mon Apr 20, 2015 4:23 am
by rhianna
This is very nice and awesome post
I like it very much
Thanks alot...