Okay, so I may be relatively new to Box2D, but I A. have coded before and B. have gotten this far without too many problems... But I can't for the life of me figure out what is going wrong 😆
Basically, I've started making a platform game for my dissertation next year - I've got dynamically creating levels, player movement, weapons and a lot of other stuff planned/sorted sorted so far - one of the weapons or utilities is a 'laser creator' type thing - you fire one pellet, it sticks to a surface, you fire another pellet, and it sticks to another surface, and a laser is created from the first to the second.

It's literally done by getting the location of each of the bodys and doing a ray-cast from one to the other.
In the function specified into the raycast, it checks what type of object the hit item is, and at the moment, (I've cut all the code back to try and find the problem) it simply draws a circle where it hits (red - block, green - laser reciever, blue - sensor, white - player) and if the object is a block, it returns 0, if anything else, it returns 1. Afterwards it joins all of the points it hits with a line, stopping at a block it hits.
This works most of the time... but more than sometimes, stuff like this happens;

the ray-cast travels from left to right, so it should hit the fist object, make a blue circle, continue, hit the second object, draw a red circle, stop.
instead, it doesn't hit the first two, hits the third, draws a red dot, CONTINUES (this is what confuses me the most) and hits the end.
I've put a trace in the function and it doesn't even recall the first two objects at all...
I recently made the raycast fire every frame (to check to see if the ray was fired the same place it would do the same thing, or whether it wouldn't) - it does the same thing while it's in the same position.
after testing (and testing) it seems to happen with certain objects, from certain positions, often when objects are next to each-other, but what happens don't seem to have too much of a patter (which seems to be no help to me).
more examples:


Here is the function for the raytrace, I can post more code, but you'll have to let me know what else you need to be of more help, because it is in all different places in different classes and whatnot
I was going to post the swf so you could have a little play with it, but it wouldn't let me attach it 😢
It's probably something really stupid I've done on my part, but this time around, whether it is or isn't, I can't figure out what it is without somebody else's help. 😕
Thanks in advance, hope you can help 😉
Basically, I've started making a platform game for my dissertation next year - I've got dynamically creating levels, player movement, weapons and a lot of other stuff planned/sorted sorted so far - one of the weapons or utilities is a 'laser creator' type thing - you fire one pellet, it sticks to a surface, you fire another pellet, and it sticks to another surface, and a laser is created from the first to the second.

It's literally done by getting the location of each of the bodys and doing a ray-cast from one to the other.
In the function specified into the raycast, it checks what type of object the hit item is, and at the moment, (I've cut all the code back to try and find the problem) it simply draws a circle where it hits (red - block, green - laser reciever, blue - sensor, white - player) and if the object is a block, it returns 0, if anything else, it returns 1. Afterwards it joins all of the points it hits with a line, stopping at a block it hits.
This works most of the time... but more than sometimes, stuff like this happens;

the ray-cast travels from left to right, so it should hit the fist object, make a blue circle, continue, hit the second object, draw a red circle, stop.
instead, it doesn't hit the first two, hits the third, draws a red dot, CONTINUES (this is what confuses me the most) and hits the end.
I've put a trace in the function and it doesn't even recall the first two objects at all...
I recently made the raycast fire every frame (to check to see if the ray was fired the same place it would do the same thing, or whether it wouldn't) - it does the same thing while it's in the same position.
after testing (and testing) it seems to happen with certain objects, from certain positions, often when objects are next to each-other, but what happens don't seem to have too much of a patter (which seems to be no help to me).
more examples:


Here is the function for the raytrace, I can post more code, but you'll have to let me know what else you need to be of more help, because it is in all different places in different classes and whatnot
Code: Select all
private function MakeLaserReturn(fixture:b2Fixture,point:b2Vec2,normal:b2Vec2,fraction:Number):Number
{
var hititem:Object = fixture.GetBody().GetUserData();
//trace(fixture.GetBody().GetUserData());
if (hititem is PlayerActor)
{
temparray.push(point);
drawCircle(point, 0xffffff);
return 1;
}else if (hititem is PlayerActorWheel)
{
temparray.push(point);
drawCircle(point, 0xffffff);
return 1;
}else if (hititem is BulletActor)
{
temparray.push(point);
drawCircle(point, 0x00ff00);
return 1;
}else if (hititem is LaserReceiver)
{
temparray.push(point);
drawCircle(point, 0x0000ff);
return 1;
}else if (hititem is PlatTileActor)
{
temparray.push(point);
drawCircle(point, 0xFF0000);
return 0;
}
return 0;
}I was going to post the swf so you could have a little play with it, but it wouldn't let me attach it 😢
It's probably something really stupid I've done on my part, but this time around, whether it is or isn't, I can't figure out what it is without somebody else's help. 😕
Thanks in advance, hope you can help 😉




