This project has moved and is read-only. For the latest updates, please go here.

Getting the angular of a polygon-edge

Topics: Developer Forum, User Forum
Oct 30, 2013 at 8:07 PM
Hey guys

First of all I don't know the right terminology for the thing I need to know.
I'm sure there would be one word which describes everything I need, but because I can't, let me show you a picture of what I need :)


Here are my thoughts, how one would have to achive that:
OnCollision, I have to figure out which Body/Fixture the Terrain is. So that's easy, also to get the Point of collision is no rocket science. But now I need to know the edge on which the collision happened. From there I could get to the 2 relating vertexes.
Last, but not least, I would have to calculate the angular, which is rather easy all thanks to trigonometry.

So what actually puzzles me is how to get these 2 vertexes from the Fixture?
Or is there another way to do that, maybe even more resource-efficient?

Thank you all very much!

Cheers Richard
Nov 5, 2013 at 1:26 AM
If you want the vertices you find them on the fixture's oncollision event like this:

PolygonShape shape = (PolygonShape)fixture.Shape;
Nov 12, 2013 at 7:41 PM
If that's the only way to do that, alright. thanks!
Nov 12, 2013 at 10:35 PM
No it's not. In fact all the information is there already. The magic thing you are looking for is called contact manifold. There is a contact provided by the OnCollisionEventHandler(Fixture fixtureA, Fixture fixtureB, Contact contact). Use contact.GetWorldManifold(out Vector2 normal, out FixedArray2<Vector2> points) to get your normal. The normal always points from fixtureA to fixtureB so you have to check which fixture belongs to the ground and which one to the character and maybe invert it. Note: The direction is dependent on the internal IDs of the bodies and not guaranteed to stay the same on different machines or even during one run of your game so you have to check every time.
Marked as answer by _RichardFrick on 11/13/2013 at 2:46 AM
Nov 13, 2013 at 10:46 AM
thanks, will do that!