Can't get angle between two points

Discuss issues specific to the Flash/AS3 port of Box2D
Posts: 21
Joined: Wed Feb 25, 2015 10:36 am

Can't get angle between two points

Postby gramcracker » Mon Aug 03, 2015 11:30 am

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.

Return to “Flash”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests