Getting the collision point from a raycast

Hello,

I'm using box2DFlash but hopefully that shouldn't change much.

I got a generated terrain using .SetAsEdge and the shape of the edge is as follows: .__
The dot being the position.Set(); and the SetAsEdge() is set relative to it's position.

Now when i have a shape colliding with the terrain i want to use a raycast from y:0 and the x corresponding to the position of the nodes, all the way down till it hits the shapes. I was hoping to be able to get the y coordinate from the point it hit the shape so that i can raise the terrain to match the height of the object.

How should i go about this and is a raycast even the way to go?
I got some rudimentary code going that should raycast correctly. I got 64 nodes in the nodelist at a certain height and i cast down from 0 till i hit a body between the origin of the ray and the node. But i'm only seeing 3 hits with some odd coordinates.

Code: Select all

HIT :0 13.214358606996637 0.03375912170885311
HIT :0 13.214358606996633 0.033759121708853104
HIT :9.999999999999998 13.296235459391028 0.033545146541476084


Any help would be greatly appreciated.

Code: Select all

private function changeGround(args:Object):void
      {   
         for(var i:int = 0; i< nodeList.length; i++)
         {
            var node:Point = nodeList[i];
            m_world.RayCast( raycastResult, new b2Vec2(node.x, 0), new b2Vec2(node.x, node.y-5) );
         }
      }
      private function raycastResult(fixture:b2Fixture, point:b2Vec2,
                              normal:b2Vec2, fraction:Number  ):Number
      {
         trace("HIT :"+point.x, point.y, fraction );
         
         return fraction;
      }

Original thread: https://box2d.org/forum/viewtopic.php?t=6554