Hi folks,
I'm having an issue very annoying. Im trying to do a raycast and the doc says that i have to pass a callback as parameter. But when i try to log something in the callback nothing happens.
Here is my code to do this little job
The main where i call my custom function "doRayCast"
And here is the code that should execute the raycast
To sum up my problem, the "callback" is not traced in the log debugger meaning that the callback is not called...
Please help me im stuck 😮 , thanks
I just solved my problem. The reason was the coordinates of my two segments were not scaled to the world. Dividing them by 30 solved it.
I just waste a whole afternon but now I"m so HAPPY 😀 😀 😀
I'm having an issue very annoying. Im trying to do a raycast and the doc says that i have to pass a callback as parameter. But when i try to log something in the callback nothing happens.
Here is my code to do this little job
The main where i call my custom function "doRayCast"
Code:
var rayCastManager:RayCastManager = new RayCastManager();
rayCastManager.doRayCast(slicingSegment, world);
rayCastManager.doRayCast(reversedSlicingSegment, world);
rayCastManager.doRayCast(slicingSegment, world);
rayCastManager.doRayCast(reversedSlicingSegment, world);
And here is the code that should execute the raycast
Code:
public function doRayCast(segment:b2Segment, world:b2World):b2Vec2
{
//Getting RayCastManager
var rayCastManager:RayCastManager = new RayCastManager();
function rayCastCallback(fixture:b2Fixture, point:b2Vec2, normal:b2Vec2, fraction:Number):Number
{
trace("Callback");
this.fixture=fixture;
this.intersectionPoint=point;
this.normal=normal;
this.fraction=fraction;
return fraction;
}
//Do Raycast and write the results with the help of the callback
world.RayCast(rayCastCallback,segment.p1,segment.p2);
/** What follows is not important as i cant fill in the fields, intersectionPoint is always null. Thus, i commented lines above**/
//Getting intersectionPoint
//var intersectionPoint:b2Vec2 = rayCastManager.getIntersectionPoint();
//trace("intersectionPointX:"+intersectionPoint.x+" intersectionPointY:"+intersectionPoint.y);
//return intersectionPoint;
return null;
}
{
//Getting RayCastManager
var rayCastManager:RayCastManager = new RayCastManager();
function rayCastCallback(fixture:b2Fixture, point:b2Vec2, normal:b2Vec2, fraction:Number):Number
{
trace("Callback");
this.fixture=fixture;
this.intersectionPoint=point;
this.normal=normal;
this.fraction=fraction;
return fraction;
}
//Do Raycast and write the results with the help of the callback
world.RayCast(rayCastCallback,segment.p1,segment.p2);
/** What follows is not important as i cant fill in the fields, intersectionPoint is always null. Thus, i commented lines above**/
//Getting intersectionPoint
//var intersectionPoint:b2Vec2 = rayCastManager.getIntersectionPoint();
//trace("intersectionPointX:"+intersectionPoint.x+" intersectionPointY:"+intersectionPoint.y);
//return intersectionPoint;
return null;
}
To sum up my problem, the "callback" is not traced in the log debugger meaning that the callback is not called...
Please help me im stuck 😮 , thanks
I just solved my problem. The reason was the coordinates of my two segments were not scaled to the world. Dividing them by 30 solved it.
I just waste a whole afternon but now I"m so HAPPY 😀 😀 😀