#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Angle between two points

Posts: 54Member
edited 8:00PM
Hey Guys,

I'm trying to find the angle between two points and from what I've been reading vectorToAngle does just that.

"Usage: vectorToAngle(x,y)

Find the angle relative to the origin, (0,0), given an X and Y coordinate. You can include an offset,(x',y'), to find an angle relative to the offset.

e.g. vectorToAngle(x-x',y-y')"

So I did this to find the angel between the player and the mouse as shown below.

vectorToAngle(( game.Mouse.Position.X - self.Position.X ),( game.Mouse.Position.Y - self.Position.Y ))

However, I was expecting a value returned in degrees but instead I am getting negative values. What am I doing wrong? :S

• Posts: 6,256Member
it should be

vectorToAngle(self.position.x-mouse.position.x,self.position.y-mouse.position.y)
• Posts: 2,402Member
You don't need the extra brackets (but I dont think thats the problem) sometimes actors just get mixed up. Try this way around.

vectorToAngle( self.Position.X - game.Mouse.Position.X , self.Position.Y - game.Mouse.Position.Y )
• Posts: 54Member
ah great that's awesome. Good spot. Thank you.

However, I am still getting results between -180 to 180. How do I get results between 0 to 360?
• Posts: 2,402Member