Howdy, Stranger!

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

Angle between two points

GuardianGuardian Posts: 54Member
Hey Guys,

I'm new to GameSalad so don't slam me too badly :D

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


  • JohnPapiomitisJohnPapiomitis Posts: 6,256Member
    it should be

  • Rob2Rob2 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 )
  • GuardianGuardian 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?
  • Rob2Rob2 Posts: 2,402Member
    add 180 :)
  • GuardianGuardian Posts: 54Member
    Well you see I thought that but I needed the angle to go clockwise so I did this.

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

    Now it all works :)

    Thanks guys! :D
This discussion has been closed.