Issue with working out distance between player position and mouse position.

Hi guys,

I am using the following to work out the distance between player position and mouse position.

sqrt((pow(( game.Mouse.Position.X - self.Position.X ), 2))+ (pow(( game.Mouse.Position.Y - self.Position.Y ),2)))

However, I have notice that as the player moves to the other side of the scene (two screen lengths) the resulting distance is also increased when relatively the positions are the same. So I have come to the conclusion that player position is relative to the scene while mouse position is relative to the screen (maybe this an incorrect assumption that needs to be corrected)

Therefore, is there anyway to work out the player position relative to the screen?

Kind regards,
Guardian

Comments

  • OniCraftOniCraft Member, BASIC Posts: 43
    I think you need something like this to have it work outside the screen size?
    This tutorial is not done by me, by the way

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Oh wow, it's the pythagorean theorem. You can certainly do it that way, but there's a built-in magnitude function that does it for you. :)
  • GuardianGuardian Member Posts: 54
    OniCraft found a fix for my problem and tatiang pointed out a way of making my equation shorter.

    Thanks guys
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I wish I had a brain for math! @tatiang I'm green with envy.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @FryingBaconStudios how funny because I feel that way about @RThurman! But thanks :)
Sign In or Register to comment.