Gravity about a point

Topics: Developer Forum, User Forum
Mar 25, 2010 at 12:39 AM
Edited Mar 25, 2010 at 7:22 AM

I am not sure if that describes it, but I want gravty to pull to a point rather than in one direction. How can I do this with Farseer? This is my first time play with Farseer, so treat me like a newb.

The basic setup would include a large sphere, and gravity would point to the center of the sphere, and be relative to the distance from the center of the sphere. Something similar to this (just a working concept, but I did not do this with Farseer):

http://playmatter.com/Lander/default.html  (click to begin, and use arrow keys for thrust and rotation)

Thanks,
Roger

 

*edit  ... I am doing this in Silverlight

Developer
Mar 25, 2010 at 2:24 AM

The easiest way to do this would be to write a custom Controller that calculates a force based on the distance and angle of a body from some point representing your worlds center of gravity. I will check into this and let you know a more definite solution as I'm not familiar with planetary style gravity.

Mar 25, 2010 at 2:27 AM

Thanks, I had just found Planetary Gravity in the manual, and am still reading...

Any help is appreciated.

Thanks!

Mar 25, 2010 at 3:02 AM

Ok, I have it working somewhat, thanks to this post:

 http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=74236

however, there is definately a 'fidgety' feel to it. How can I go about smothing it out? This is just a small 'planet' I hope to do all this with a very large one.

paste this into the Initialize for demo2

     ClearCanvas();
            
            int planetRadius = 200;
            Vector2 planetPosition = new Vector2(725, 684);

            ClearCanvas();
            physicsSimulator = new PhysicsSimulator();

            Body rectangleBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 128, 128, 1);
            rectangleBody.Position = new Vector2(256, 384);

            Geom rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, rectangleBody, 128, 128);
            rectangleGeom.CollisionGroup = 15;

            Body circleBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, planetRadius, 100);
            circleBody.IsStatic = true;
            circleBody.Position = planetPosition;

            Geom circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, circleBody, planetRadius, 2000);
            circleGeom.CollisionGroup = 14124;

            AddRectangleToCanvas(rectangleBody, new Vector2(128, 128));
            AddCircleToCanvas(circleBody, planetRadius);
            controlledBody = rectangleBody;

            List<Body> bodies = new List<Body>();
            bodies.Add(rectangleBody);

            GravityController gravityCont = ComplexFactory.Instance.CreateGravityController(physicsSimulator, bodies, GravityType.DistanceSquared, 100000000, 5000);
            gravityCont.PointList = new List<Vector2>();
            gravityCont.PointList.Add(planetPosition);

            physicsSimulator.ControllerList.Add(gravityCont);
            base.Initialize();
Mar 25, 2010 at 3:30 AM

Ok, this is getting a little better... now I need to learn about friction. I am hoping that could improve how the object is a little to 'jumpy'.

            int planetRadius = 800;
            int gravityRadius = planetRadius + 1000;
            GravityType type = GravityType.Linear;
            float gravityStrength = 1000000;
            Vector2 planetPosition = new Vector2(planetRadius/2 + 700, planetRadius/2 + 684);

            ClearCanvas();
            physicsSimulator = new PhysicsSimulator();

            Body rectangleBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 128, 128, 1);
            rectangleBody.Position = new Vector2(256, 384);

            Geom rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, rectangleBody, 128, 128);
            rectangleGeom.CollisionGroup = 15;

            Body circleBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, planetRadius, 100);
            circleBody.IsStatic = true;
            circleBody.Position = planetPosition;

            Geom circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, circleBody, planetRadius, 2000);
            circleGeom.CollisionGroup = 14124;

            AddRectangleToCanvas(rectangleBody, new Vector2(128, 128));
            AddCircleToCanvas(circleBody, planetRadius);
            controlledBody = rectangleBody;

            List<Body> bodies = new List<Body>();
            bodies.Add(rectangleBody);

            GravityController gravityCont = ComplexFactory.Instance.CreateGravityController(physicsSimulator, bodies, GravityType.Linear, gravityStrength, gravityRadius);
            gravityCont.PointList = new List<Vector2>();
            gravityCont.PointList.Add(planetPosition);

            physicsSimulator.ControllerList.Add(gravityCont);