Angle between two points

GuardianGuardian Member Posts: 54
edited November -1 in Working with GS (Mac)
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

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    it should be

    vectorToAngle(self.position.x-mouse.position.x,self.position.y-mouse.position.y)
  • Rob2Rob2 Member Posts: 2,402
    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 Member Posts: 54
    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 Member Posts: 2,402
    add 180 :)
  • GuardianGuardian Member Posts: 54
    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
Sign In or Register to comment.