detecting a radius around an actor

digitalzerodigitalzero Member, BASIC Posts: 639

i need help detecting the radius around an actor... i already have the game attribute of the players x and y and i think that may be a good start but what should i do after that... i have abs(self.position.x-game.playerx) > 100 then activate and its been working so far but now i am needing it to activate when its in a specific radius around the actor

Comments

  • tiger27tiger27 Member Posts: 127

    What do you mean the "radius"?

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @digitalzero said:
    i need help detecting the radius around an actor... i already have the game attribute of the players x and y and i think that may be a good start but what should i do after that... i have abs(self.position.x-game.playerx) > 100 then activate and its been working so far but now i am needing it to activate when its in a specific radius around the actor

    Like @tiger27 says, your use of radius in this context is a little vague.

    Using your formula [abs(self.position.x-game.playerx) >100] then the 'radius' would be 100 (although the distance would be linear rather than radial) - so in that respect it is already specific (it's 100).

    I think it's magnitude you are after (?), but I'm not 100% sure.

    Magnitude gives you this distance between two actors (in any direction) and it works like this: the distance between A and B . . .

    magnitude(B.position.x-A.position.x, B.position.y-A.position.y)

  • digitalzerodigitalzero Member, BASIC Posts: 639

    MAGNITUDE IS EXACTLY WHAT IM LOOKING FOR @Socks SO HOW WOULD I BE ABLE TO ACHIEVE THAT... im also going to do some searching in the forum too now that i know what im looking for lol

  • SocksSocks London, UK.Member Posts: 12,822

    @digitalzero said:
    HOW WOULD I BE ABLE TO ACHIEVE THAT...

    Magnitude gives you this distance between two actors (in any direction) and it works like this: the distance between A and B . . .

    magnitude(B.position.x-A.position.x, B.position.y-A.position.y)

  • digitalzerodigitalzero Member, BASIC Posts: 639

    so okay which actor would i put first... so would it go something like self.positionx-game.playerx, self.positiony-game.playery is equal or greater then 100? or how does that go?

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @digitalzero said:
    so okay which actor would i put first...

    Magnitude gives you the distance between the two actors.

    The distance between two objects doesn't change if you measure it from A to B or B to A, the distance will remain the same, if you do find that the distance is different depending on which direction you make the measurement then contact the The Institute of Physics in London, there is a Nobel Prize waiting for you !! :smiley: :tongue:

    @digitalzero said:
    so would it go something like self.positionx-game.playerx, self.positiony-game.playery is equal or greater then 100? or how does that go?

    Exactly as you describe . . .

    When [numeric expression] magnitude(actor1.x - actor2.x , actor1.y - actor2.y) > 100
    --Then do something.

  • digitalzerodigitalzero Member, BASIC Posts: 639

    IVE GOT IT! THANKS SO MUCH @SOCKS!

Sign In or Register to comment.