(text taken from here: http://box2dxna.codeplex.com/Thread/View.aspx?ThreadId=211636)
Hi,
i'm developing a game called Warlock Football as my bachelor thesis and i'm using your Box2D port. Although i'm not sure if I should post the question here, I'll try it. In worst case please redirect me somewhere else 🙂
I have a problem with motion of th warlocks who are basically moved by player. In this case they can either move forward or backward and then they can turn right and left. The first is made by applying force to their bodies and the other by applying torque. To limit the speed and rotation speed I use linear and angular damping, but since they are "humans" the movement should have very high acceleration and they should stop immediatelly when you stop pressing the movement key. I handle this by applying quite big force and torque and setting damping quite high, but still it makes the movement float-like. I have also considered setting their linear and angular velocities directly, but then I'm afraid that I'd screw the whole physics, for isntance when there would be an explosion near by, you'd able to escape its physical consequences by pressing movement key and thus overriding the applied forces. Has anyone any answer to such a question? (I actually hope that I have explained myself clearly and understandably 🙂
In addition here is the body definition code:
// define his body
var bodyDef = new BodyDef();
bodyDef.type = BodyType.Dynamic;
bodyDef.position = position;
bodyDef.angle = angle;
bodyDef.bullet = false;
bodyDef.active = true;
bodyDef.fixedRotation = false;
bodyDef.allowSleep = false;
bodyDef.linearDamping = 4.5f; // DAMPING HERE
bodyDef.angularDamping = 5.0f;
// define his shape
var circleShape = new CircleShape();
circleShape._radius = 1.4f;
// define fixture using his shape
var fixtureDef = new FixtureDef();
fixtureDef.shape = circleShape;
fixtureDef.density = 10.0f;
fixtureDef.friction = 0.0f;
fixtureDef.restitution = 0.0f;
// forward force and torque for SteeringComponent <- FORCES FOR MOVEMENT
float forwardForce = 2800.0f;
float torque = 1200.0f;
And the way I apply forces for movement:
// check movement flags and apply forces accordingly
if ((Move & Movement.Forward) == Movement.Forward)
{
Vector2 force = new Vector2((float)Math.Cos(physicalBodyComponent.Angle), (float)Math.Sin(physicalBodyComponent.Angle));
force *= forwardForce;
physicalBodyComponent.ApplyForce(force, physicalBodyComponent.Position);
}
if ((Move & Movement.Backward) == Movement.Backward)
{
Vector2 force = Vector2.Negate(new Vector2((float)Math.Cos(physicalBodyComponent.Angle), (float)Math.Sin(physicalBodyComponent.Angle)));
force *= forwardForce;
physicalBodyComponent.ApplyForce(force, physicalBodyComponent.Position);
}
if ((Move & Movement.TurnLeft) == Movement.TurnLeft)
{
physicalBodyComponent.ApplyTorque(-torque);
}
if ((Move & Movement.TurnRight) == Movement.TurnRight)
{
physicalBodyComponent.ApplyTorque(torque);
}
Hi,
i'm developing a game called Warlock Football as my bachelor thesis and i'm using your Box2D port. Although i'm not sure if I should post the question here, I'll try it. In worst case please redirect me somewhere else 🙂
I have a problem with motion of th warlocks who are basically moved by player. In this case they can either move forward or backward and then they can turn right and left. The first is made by applying force to their bodies and the other by applying torque. To limit the speed and rotation speed I use linear and angular damping, but since they are "humans" the movement should have very high acceleration and they should stop immediatelly when you stop pressing the movement key. I handle this by applying quite big force and torque and setting damping quite high, but still it makes the movement float-like. I have also considered setting their linear and angular velocities directly, but then I'm afraid that I'd screw the whole physics, for isntance when there would be an explosion near by, you'd able to escape its physical consequences by pressing movement key and thus overriding the applied forces. Has anyone any answer to such a question? (I actually hope that I have explained myself clearly and understandably 🙂
In addition here is the body definition code:
// define his body
var bodyDef = new BodyDef();
bodyDef.type = BodyType.Dynamic;
bodyDef.position = position;
bodyDef.angle = angle;
bodyDef.bullet = false;
bodyDef.active = true;
bodyDef.fixedRotation = false;
bodyDef.allowSleep = false;
bodyDef.linearDamping = 4.5f; // DAMPING HERE
bodyDef.angularDamping = 5.0f;
// define his shape
var circleShape = new CircleShape();
circleShape._radius = 1.4f;
// define fixture using his shape
var fixtureDef = new FixtureDef();
fixtureDef.shape = circleShape;
fixtureDef.density = 10.0f;
fixtureDef.friction = 0.0f;
fixtureDef.restitution = 0.0f;
// forward force and torque for SteeringComponent <- FORCES FOR MOVEMENT
float forwardForce = 2800.0f;
float torque = 1200.0f;
And the way I apply forces for movement:
// check movement flags and apply forces accordingly
if ((Move & Movement.Forward) == Movement.Forward)
{
Vector2 force = new Vector2((float)Math.Cos(physicalBodyComponent.Angle), (float)Math.Sin(physicalBodyComponent.Angle));
force *= forwardForce;
physicalBodyComponent.ApplyForce(force, physicalBodyComponent.Position);
}
if ((Move & Movement.Backward) == Movement.Backward)
{
Vector2 force = Vector2.Negate(new Vector2((float)Math.Cos(physicalBodyComponent.Angle), (float)Math.Sin(physicalBodyComponent.Angle)));
force *= forwardForce;
physicalBodyComponent.ApplyForce(force, physicalBodyComponent.Position);
}
if ((Move & Movement.TurnLeft) == Movement.TurnLeft)
{
physicalBodyComponent.ApplyTorque(-torque);
}
if ((Move & Movement.TurnRight) == Movement.TurnRight)
{
physicalBodyComponent.ApplyTorque(torque);
}