
Hey everyone,
I am trying to shoot some bullets from a tank, and they seem to be flying off in the wrong direction. I'm sure it's a simple math problem that I've overlooked.
Basically it gets the rotation and pitch of the tank turret.
direction.X += (10.0f * (float)Math.Sin(tank.TurretRotation  (float)Math.PI / 2));
direction.Z += (10.0f * (float)Math.Cos(tank.TurretRotation  (float)Math.PI / 2));
direction.Y += (10.0f * (float)Math.Sin(tank.TurretPitch));
which this should give me the direction vector. What I do next is in my bullet controller:
foreach (Bullet b in bullets)
{
if (b.Alive && b.NeedsImpulse)
{
bulletVelocity = Vector3.Normalize(b.Direction);
bulletVelocity *= 300.0f;
b.Body.ApplyBodyImpulse(bulletVelocity);
b.NeedsImpulse = false;
}
}
Basically if the bullet hasn't yet had an impulse applied to it, apply the impulse to 'fire' the bullet in the specified direction. The only thing is though that the more I increase the multiplier (300.0f) the more the velocity is wrong. When the turret is
at a 90, 18, 270 or 0 degree horizontal angle, the bullet lines up with the crosshair, but anything in between it is off by at most 45 degrees.
Thanks everyone


Coordinator
Oct 11, 2008 at 10:57 AM

maybe its a problem with the limited velocity.
have a look here:
http://jiglibx.wikidot.com/forum/t95780/strangeresultswithlargevelocityorimpulse

