Help! My math apparently sucks (Line Query)

Discuss new features and future development.

Help! My math apparently sucks (Line Query)

Postby mster50 » Thu Aug 04, 2011 12:17 pm

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.
mster50
 
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am

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

Postby slembcke » Thu Aug 04, 2011 1:16 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

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

Postby mster50 » Thu Aug 04, 2011 4:19 pm

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.
mster50
 
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am

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

Postby slembcke » Thu Aug 04, 2011 4:59 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

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

Postby mster50 » Thu Aug 04, 2011 5:19 pm

Ah yes, excellent. I think I can fix this up then, thanks Scott. You're awesome.
mster50
 
Posts: 3
Joined: Thu Aug 04, 2011 7:32 am

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

Postby rhianna » Mon Apr 20, 2015 4:23 am

This is very nice and awesome post
I like it very much
Thanks alot...
Lily lara
rhianna
 
Posts: 1
Joined: Mon Apr 20, 2015 4:09 am


Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron