RayCast skipping tiles if to close?

Topics: User Forum
May 15, 2011 at 4:13 PM

Hi. Im making a 2d platformer/puzzle game and I want the player to be able to shoot tiles to destroy them.

yesterday I started using RayCast but I get a verry desturbing result. If im standing on a distance there´s no problem in detecting the closest fixture but if the player is close to the tile or if the ray enters a fixture in a wierd angle the ray totally ignores that fixture.

Is there someone who knows what might cause this or if theres a way to improve the quality of the ray?

This is the raycast code:

//check what point the player aim�s on
            if (padState.IsButtonDown(Buttons.B) == true)
                world.RayCast((fixture, point, normal, fraction) =>
                    tempVector2 = point; return fraction;
                , player.body.Position, player.aimPos / MeterInPixels);

This is the raycast code:

class ConcreteBlock
        public Body body;
        public Texture2D texture;
        public Fixture fix;

        public void Create(World world, SFX sfx, float MeterInPixels, int x, int y, Texture2D tex)
            texture = tex;
            Vector2 blockPosition = new Vector2(x, y);
            body = BodyFactory.CreateRectangle(world, 50f / MeterInPixels, 50f / MeterInPixels, 1f, blockPosition);
            body.IsStatic = false;
            body.BodyType = BodyType.Static;
            body.Restitution = 0f;
            body.Friction = 0.5f;
            body.UserData = (int)1;

            fix = FixtureFactory.AttachRectangle( 50f / MeterInPixels, 50f / MeterInPixels,1f,Vector2.Zero,body);
            sfx.DrawAdd(false, tex, body.Position * MeterInPixels, new Vector2(tex.Width / 2f, tex.Height / 2f), Vector2.Zero, Vector2.Zero, body.Rotation, 0f, new Vector2(1f, 1f), Vector2.Zero, 0f);

May 15, 2011 at 7:39 PM

I have seen the same thing. At certain angles the ray seems to shoot right through EdgeShapes. I wonder if this is a bug.

May 15, 2011 at 8:13 PM

I looked at the testbed and it seems like it has the same issue when many fixtures are present. Can anyone look in to this?

Allso is there any other way to do this?

May 21, 2011 at 2:09 PM

Hrmm. Surprised nobody has replied to this. Seems like a pretty big bug to me.

May 23, 2011 at 3:35 PM

I'm having a similar problem (raycasting ignoring some fixtures at sometimes), but I've been quite busy on other stuff so I haven't had time to check where the error could be. Anyway, I hope this at least gives you a little consolation by knowing that you are not alone. Sorry I can't help you further.

May 23, 2011 at 5:56 PM

Thanks for the reply, I was pretty sure it was an issue, but there is always at the back of my mind that I could be doing something wrong. It seems to be dependent on the angle the ray hits the bodies, as it works perfectly in the testbed example.

I haven't had a chance to look into this either yet, not had much time to work on my projects for a while. Hopefully I'll get a chance to look into it soon and if I find anything I will post back here.