This project has moved and is read-only. For the latest updates, please go here.

2.1.3 tunneling can i add ccd?

Jul 14, 2011 at 8:37 PM

Hi there, i have a project in developement that uses farseer 2.1.3 and i have a tunneling problem. My fast moving bullets pass through walls. Is there a relatively pain free way for me to add CCD by updating or adding some modifications to any of the code in the physics engine to simply solve this problem and not mean i have to start my project over again. for example, if i could simply copy in a CCD method or class into class PhysicsSimulator ect...

Jul 14, 2011 at 10:08 PM

Sorry but CCD is quite complicated. I did attempt to add it to my SAT based narrow phase and failed at creating realistic response. One way to help prevent CCD would be to make your bullets longer without actually changing there rendered size.

Jul 15, 2011 at 8:42 AM

Yes i've tried this but the problem is that the bullets still partially pass through the wall before they detect collision, which means that someone sitting the other side could still potentially be shot. I also seem to have a problem with drawing the bullet in the right place on the Geom. I seem to be getting problems with rotation and all sorts, i struggle to configure the bullet so that it draws at the end of the geom and rotates around the centre of the image. Here's what i have at the moment:

    class Bullet
        #region Variables
        public Body bulletBody;
        public Geom bulletGeom;
        Vector2 bulletOrigin;
        Texture2D bulletTex;
        KeyboardState keyState;
        Vector2 velocity;

        public Bullet(Texture2D bulletTex, Vector2 position, Vector2 velocity, Camera2D cam)
            this.bulletTex = bulletTex;
            this.bulletOrigin = new Vector2(bulletTex.Width / 2, bulletTex.Height / 2);
            this.velocity = velocity;

            bulletBody = BodyFactory.Instance.CreateRectangleBody(bulletTex.Width, bulletTex.Height * 10f, 0.5f);
            bulletBody.Position = position;
            bulletBody.LinearVelocity = velocity;

            float collisionLength = velocity.Length();
            Vertices verts = new Vertices();
            verts.Add(new Vector2(0, 0));
            verts.Add(new Vector2(3, 0));
            verts.Add(new Vector2(3, collisionLength / 8));
            verts.Add(new Vector2(0, collisionLength / 8));
            bulletGeom = GeomFactory.Instance.CreatePolygonGeom(bulletBody, verts, new Vector2(0, 0), 0, 0);
            bulletGeom.CollisionGroup = 1;
            bulletGeom.RestitutionCoefficient = 0f;
            bulletGeom.FrictionCoefficient = 0f;

            bulletBody.Rotation = StaticHelpers.TurnToFace(bulletGeom.Position,
                new Vector2(Mouse.GetState().X + cam.TLCorner.X, Mouse.GetState().Y + cam.TLCorner.Y),
                bulletGeom.Rotation, 20f) +

        public void Update(Camera2D cam)
            keyState = Keyboard.GetState();           


        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
            Vector2 velocityNorm = velocity;
                bulletGeom.Position + (velocityNorm * (velocity.Length() / 400)),

Jul 17, 2011 at 11:25 PM
Edited Jul 17, 2011 at 11:26 PM

In case anyone comes across this thread, i opted to upgrade to version 3.2 in the end. Somewhat time consuming but i just had to bite the bullet ;) The only reason i didn't go for version 3.3.1 (the latest at the time of writing) is that i just can't find any helpful tutorials ect to get me started.