MSTerrain issue.

Topics: Developer Forum, User Forum
Jan 26, 2012 at 11:42 PM

My issue is that no matter what I do, I can't seem to get it to work at all.

The code:

private void InitTerrain()
            _terraintex = HelperFunctions.Load2DTexture(this, "Textures/terrain");

            _terrain = new MSTerrain(_world, new AABB(Vector2.Zero, 102.4f, 76.8f))
                Decomposer = Decomposer.Bayazit,
                PointsPerUnit = 10,
                CellSize = 50,
                SubCellSize = 5,
                Iterations = 2

            _terrain.ApplyTexture(_terraintex, Vector2.Zero, InsideTerrainTest);

        private bool InsideTerrainTest(Color color)
            return color == Color.Black;

        private void InitPlayer()
            _playertex = HelperFunctions.Load2DTexture(this, "Textures/player");

            _player = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(_playertex.Width), ConvertUnits.ToSimUnits(_playertex.Height), 1.0f);
            _player.Position = new Vector2(ConvertUnits.ToSimUnits(200.0f), ConvertUnits.ToSimUnits(25.0f));
            _player.Mass = 250.0f;
            _player.BodyType = BodyType.Dynamic;

No matter what I do, the player just passes directly through the terrain at the bottom of it, and collision works at completely random spots where the platforms are (sometimes in thin air!). Here's the texture:

I honestly have no clue what I'm doing wrong. :( Any help would be appreciated.

Jan 28, 2012 at 3:44 AM

Hi Eternalspirit,

I spent a week hassling with trying to make the MSTerrain class work like I wanted. One thing I noticed strange about my instance was that the terrain was rendering upside down. I am sorry, but I do not recall what I did to fix it and I've done a complete refactoring of the class at this point.

One thing I had to do was change PointsPerUnit to equal 100 instead of 10 (for Farseer 3.3.1). This will also make you need to change:

_terrain = new MSTerrain(_world, new AABB(Vector2.Zero, 102.4f, 76.8f))


_terrain = new MSTerrain(_world, new AABB(Vector2.Zero, 10.24f, 7.68f))

I'm still horribly horribly lost on the whole MSTerrain class myself. If you can, I would suggest researching how to copy in and use the DebugViewXNA class that comes with the Farseer TestBed so that you can draw your physics bodies on screen. This is the only way I was able to see exactly how the terrain was being drawn. I am sorry for the probably not very helpful response, but I'm completely new to all of this: XNA, Farseer, and game development in general. I just wanted to offer anything I thought might help.

Jan 30, 2012 at 7:19 PM

I've tried changing to 100 points per unit, but that didn't help. I checked out the TestBed for Farseer to try to figure out what all the data members of MSTerrain are, and I think I might have figured a little bit out, but for the most part, I'm completely clueless on it. The documentation for this project isn't great, really. I might just do my terrain the down and dirty way.. create a lot of bodies for the entire terrain manually.