http://www.sketchbookgames.com/Raycast.asRaycast.as class
built for use with WCK_libs TestBed
just add Raycast to the Main.as tests Array.
attempts to run a ray cast between left circle and right circle, raycast does not register center circle. not sure what I'm doing wrong.
also at certain angles i get an error
Quote:
Assertion failed: (0.0f <= lower && lower <= input.maxFraction), function RayCast, file ../Box2D/Collision/Shapes/b2PolygonShape.cpp, line 253.
[object AlchemyExit]
at <anonymous>()
at <anonymous>()
at Box2DAS.Dynamics::b2World/RayCast()
at Raycast/doRaycast()
at Raycast/EnterFrame()
at Main$/handleEnterFrame()
here is the relevent function:
Code:
private function doRaycast():void{
var p1:V2 = l.GetWorldCenter()
var p2:V2 = r.GetWorldCenter()
this.RayCast(GetBodyCallback, new V2(p1.x, p1.y), new V2(p2.x, p2.y));
var f:b2Fixture;
var lambda:Number = 1;
function GetBodyCallback(fixture:b2Fixture, point:V2, normal:V2, fraction:Number):Number{
f = fixture;
f.m_body.GetUserData().alpha -= .2
lambda = fraction
return lambda
}
p1.multiplyN(30)
p2.multiplyN(30)
drawOn.graphics.clear();
drawOn.graphics.lineStyle(2,0xff0000,1);
drawOn.graphics.moveTo(p1.x, p1.y);
drawOn.graphics.lineTo( (p2.x * lambda + (1 - lambda) * p1.x),
(p2.y * lambda + (1 - lambda) * p1.y) );
}