Body will not accept any torque

Dec 21, 2011 at 3:20 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FarseerPhysics;
using FarseerPhysics.Collision;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Controllers;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;


namespace The_System
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        World _world = new World(new Vector2(0, (float)0.5));
        Body floorBody;
        Platform[] platforms;

        Body CharBody;
        Sprite CharSprite;
        bool applied = false;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            platforms = new Platform[10];

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Texture2D text = Content.Load<Texture2D>("21323_25_25_cache");

            for (uint i = 0; i < 10; i++)
            {
                Platform p = new Platform(_world, new Vector2(i * 25, 200f), new Vector2(25f, 25f), text);
                platforms[i] = p;
            }
            
            floorBody = BodyFactory.CreateEdge(_world, ConvertUnits.ToSimUnits(0f, 481f), ConvertUnits.ToSimUnits(800f, 481f));
            floorBody.BodyType = BodyType.Static;

            CharBody = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(35f), 0f, ConvertUnits.ToSimUnits(35f, 35f));
            CharBody.Friction = 0;
            CharBody.BodyType = BodyType.Dynamic;
            //CharBody.Rotation = (float)(0 * (Math.PI / 180));

            Texture2D text2d = Content.Load<Texture2D>("Circle");
            CharSprite = new Sprite(text2d, new Vector2(35,35));

            //Path path = new Path();
            //path.Add(new Vector2(ConvertUnits.ToSimUnits(100), 0));
            //path.Add(new Vector2(ConvertUnits.ToSimUnits(100), ConvertUnits.ToSimUnits(10)));
            //path.Closed = true;

            //List<Shape> shapes = new List<Shape>(1);
            //shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(ConvertUnits.ToSimUnits(12.5f), ConvertUnits.ToSimUnits(12.5f), ConvertUnits.ToSimUnits(-12.5f,-12.5f), 0f), 0));
            //bodies = PathManager.EvenlyDistributeShapesAlongPath(_world, path, shapes, BodyType.Dynamic, 6);
            //PathManager.AttachBodiesWithRevoluteJoint(_world, bodies, ConvertUnits.ToSimUnits(12.5f, 25f), ConvertUnits.ToSimUnits(12.5f, 0), false, false);

            //t2d = new Sprite(text);


        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            KeyboardState ks = Keyboard.GetState();
            if (ks.IsKeyUp(Keys.D))
            {
                CharBody.ApplyTorque(-1000);
            }
            if (ks.IsKeyDown(Keys.A))
            {
                CharBody.ApplyTorque(1000);
            }
            

            //Update Farseer _world
            _world.Step(1f/60f);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            for (uint i = 0; i < 10; i++)
            {
                platforms[i].Draw(spriteBatch);
            }
            //for (uint i = 0; i < (bodies.Count - 1); i++)
            //{
            //    spriteBatch.Draw(t2d.Texture, ConvertUnits.ToDisplayUnits(bodies[(int)i].Position), new Rectangle(0,0,25,25), Color.White, 0f, t2d.Origin, new Vector2(1f, 1f), SpriteEffects.None, 0f);
            //}
            spriteBatch.Draw(CharSprite.Texture, ConvertUnits.ToDisplayUnits(CharBody.Position), null, Color.White, CharBody.Rotation, CharSprite.Origin, 1f, SpriteEffects.None, 0f);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}

I'm using XNA 4.0 and FPE 3.3.1 if that helps. CharBody doesn't move or rotate.
Dec 21, 2011 at 3:16 PM

Did you try to simply use a greater force than 1000? Also is it .Step that is used now in 3.3.1 and not Update? I assume the rest of Farseer is working?

Dec 22, 2011 at 3:47 AM

Yes I did use a force greater than 1000. .Step is used in 3.3.1 as far as I can tell because the rest of Farseer works...