I'm getting really frustrated here. I've tried every solution there is to get the angle between two objects
and I get some angles that don't correspond to anything, or indicate any relationship of positioning.
function angleCalc (x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x2 - x1;
var dy:Number = y2 - y1;
var j:Number = Math.atan2(dy,dx) * Constants.RADIANS_TO_DEGREES;
return j;
}
var targetAngle:Number = angleCalc(car.GetPosition().x * Constants.PIXELS_TO_METRE,
(car.GetPosition().y * Constants.PIXELS_TO_METRE) - 20,
bombObject.body.GetPosition().x * Constants.PIXELS_TO_METRE,
bombObject.body.GetPosition().y * Constants.PIXELS_TO_METRE);
The angle ends up making no sense, being the opposite of where it's supposed to be.
I convert the angle to a vector and impulse it
var impulse = new b2Vec2(Math.cos(targetAngle) * 30, Math.sin(targetAngle) * 30);
ball.body.ApplyForce(impulse, ball.body.GetWorldCenter());
This is probably a failure of Flash, it fails it so many ways.
and I get some angles that don't correspond to anything, or indicate any relationship of positioning.
function angleCalc (x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x2 - x1;
var dy:Number = y2 - y1;
var j:Number = Math.atan2(dy,dx) * Constants.RADIANS_TO_DEGREES;
return j;
}
var targetAngle:Number = angleCalc(car.GetPosition().x * Constants.PIXELS_TO_METRE,
(car.GetPosition().y * Constants.PIXELS_TO_METRE) - 20,
bombObject.body.GetPosition().x * Constants.PIXELS_TO_METRE,
bombObject.body.GetPosition().y * Constants.PIXELS_TO_METRE);
The angle ends up making no sense, being the opposite of where it's supposed to be.
I convert the angle to a vector and impulse it
var impulse = new b2Vec2(Math.cos(targetAngle) * 30, Math.sin(targetAngle) * 30);
ball.body.ApplyForce(impulse, ball.body.GetWorldCenter());
This is probably a failure of Flash, it fails it so many ways.