Help! My math apparently sucks (Line Query)

Discuss new features and future development.
Post Reply
mster50
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am
Contact:

Help! My math apparently sucks (Line Query)

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

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

Post 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
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mster50
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am
Contact:

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

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

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

Post by slembcke »

If it's a circle shape then you can do cpCircleShapeGetRadius().
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mster50
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am
Contact:

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

Post by mster50 »

Ah yes, excellent. I think I can fix this up then, thanks Scott. You're awesome.
rhianna
Posts: 1
Joined: Mon Apr 20, 2015 4:09 am
Contact:

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

Post by rhianna »

This is very nice and awesome post
I like it very much
Thanks alot...
Lily lara
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests