Hi,
I'm trying to convert my moving mechanics from manualy steering to force steering in Farseer and i have no idea how to do it. I'm working on Asteroids clone with extended mechanics. Before, I was using this algorithm to moving ship:
if (key.IsKeyDown(Keys.Space))
{
if (currentAcceleration < maxAcceleration)
{
currentAcceleration += acceleration;
}
velocity.X += (float)(Math.Sin(angle) * currentAcceleration);
velocity.Y += (float)(Math.Cos(angle) * currentAcceleration);
}
if (key.IsKeyDown(Keys.V))
{
velocity.X = 0.0f;
velocity.Y = 0.0f;
}
if (oldKey.IsKeyDown(Keys.Space) && key.IsKeyUp(Keys.Space))
{
currentAcceleration = 0.0f;
}
oldKey = key;
position.X += velocity.X;
position.Y += velocity.Y;
spriteRectangle.X = (int)(position.X + 0.5f);
spriteRectangle.Y = (int)(position.Y + 0.5f);
As you see, my ship accelerating only when space button is pushed. I can every time turn back it pointing it in the opposite direction and adding acceleration. In my force algorithm it seems to like once added force stayed there forever and ship accelerating
all time. How to fix it?
if (key.IsKeyDown(Keys.Space))
{
if (currentForce < maxForce)
{
currentForce += forceValue;
}
force.X += (float)(Math.Sin(angle) * currentForce);
force.Y += (float)(Math.Cos(angle) * currentForce);
}
if (oldKey.IsKeyDown(Keys.Space) && key.IsKeyUp(Keys.Space))
{
currentForce = 0.0f;
}
oldKey = key;
polygonBody.ApplyLinearImpulse(ConvertUnits.ToSimUnits(force));
