Hello, im new to box2d, but i have had some experience with physics engines on haxe.
I am trying to make a simple raycast, the raycasting part i just copied from the testbed example, On a level with lots of small rectangles raycasts miss quite often. I attached a swf so you can see the problem, press arrowkeys to move, and ctrl to raycast. If the shooter is on the left and bottom side the rays are quite accurate but as it gets further it misses a lot of obstacles. If you have any idea how to make this work help me pretty please
on the swf attached press ctrl to raycast and see the problem with some bodies
I am trying to make a simple raycast, the raycasting part i just copied from the testbed example, On a level with lots of small rectangles raycasts miss quite often. I attached a swf so you can see the problem, press arrowkeys to move, and ctrl to raycast. If the shooter is on the left and bottom side the rays are quite accurate but as it gets further it misses a lot of obstacles. If you have any idea how to make this work help me pretty please
Code:
//apparatus.as
public function ray(target:b2Vec2):void {
var p1:b2Vec2 = body.GetPosition()
var p2:b2Vec2 = target;
var f:b2Fixture = app.world.RayCastOne(p1, p2);
var lambda:Number = 1;
if (f){
var input:b2RayCastInput = new b2RayCastInput(p1, p2);
var output:b2RayCastOutput = new b2RayCastOutput();
f.RayCast(output, input);
lambda = output.fraction;
}
DebugDraw.graphics.lineStyle(1, 0xff0000, 1);
DebugDraw.graphics.moveTo(p1.x * app.RATIO, p1.y * app.RATIO);
DebugDraw.graphics.lineTo((p2.x * lambda + (1 - lambda) * p1.x) * app.RATIO, (p2.y * lambda + (1 - lambda) * p1.y) * app.RATIO);
//gets called like this apparat.ray(actors[0].body.GetPosition());
}
public function ray(target:b2Vec2):void {
var p1:b2Vec2 = body.GetPosition()
var p2:b2Vec2 = target;
var f:b2Fixture = app.world.RayCastOne(p1, p2);
var lambda:Number = 1;
if (f){
var input:b2RayCastInput = new b2RayCastInput(p1, p2);
var output:b2RayCastOutput = new b2RayCastOutput();
f.RayCast(output, input);
lambda = output.fraction;
}
DebugDraw.graphics.lineStyle(1, 0xff0000, 1);
DebugDraw.graphics.moveTo(p1.x * app.RATIO, p1.y * app.RATIO);
DebugDraw.graphics.lineTo((p2.x * lambda + (1 - lambda) * p1.x) * app.RATIO, (p2.y * lambda + (1 - lambda) * p1.y) * app.RATIO);
//gets called like this apparat.ray(actors[0].body.GetPosition());
}
on the swf attached press ctrl to raycast and see the problem with some bodies