Create indefinitely oscillating pendulum in Farseer Physics 3.3.1/Box2d
Posted
by
GONeale
on Game Development
See other posts from Game Development
or by GONeale
Published on 2012-04-15T06:03:50Z
Indexed on
2012/04/15
11:49 UTC
Read the original article
Hit count: 281
I am new to Farseer Physics and using version 3.3.1. I am after some help and would even be happy to receive Box2d answers just to ensure I get a response as I should then be able to convert it! -- Thanks
...After a lot of tinkering around I have managed to produce a thin vertical rectangle shape on the screen and I wish this to swing back and forth pinned at the top up to an angle I set (90 degrees would be fine for this sample).
When it is approaching the top I wish it to slow down, then fall back the way it just came, increase speed then obviously slow to a stop at the top again. Almost how a swinging pirate ship would work at a theme park.
This is the code I have so far which swings the shape, but it is seeming to lose speed on each swing eventually grinding to a halt:
float playerWidth = ConvertUnits.ToSimUnits(5), playerHeight = ConvertUnits.ToSimUnits(68);
playerPosition = ConvertUnits.ToSimUnits(-350, 0);
playerBody = BodyFactory.CreateRectangle(World, playerWidth, playerHeight, 2f, playerPosition);
playerBody.BodyType = BodyType.Dynamic;
// create player sprite based on player body
_rectangleSprite = new Sprite(ScreenManager.Assets.TextureFromShape(playerBody.FixtureList[0].Shape, MaterialType.Player, Color.Orange, 1f));
// Create swinging joint
var joint = JointFactory.CreateFixedRevoluteJoint(World, playerBody, ConvertUnits.ToSimUnits(0, -34), playerBody.Position);
If somebody could also provide the command I would need to pause the shape on a mouse click or keyboard command at it's current angle and then continue when I let go of the mouse click that would be super fantastic!
(I actually posted this on StackOverflow as well before I realised there was a dedicated game development forum)
Cheers
© Game Development or respective owner