Help figuring out an expression

rhinokeyrhinokey Member Posts: 158
edited July 2012 in Working with GS (Mac)
ok i have a block , i would like for when my character approaches the block from one direction with a key pressed for it to switch to another model when he gets within range

i have every thing working but the thing to tell him the range, i have on the object itself ,
when button push is true,
when character direction is 1 ( heading right)
(heres where i can't figure it out)
and game.characterx is > (self.position.x)-60 (60 is the amount of pixels away from the center of the object that i want the effect to start

now it works fine but prob is even if you are on the other side of the object walking away it will still keep going because the >-60 has no limit, so even if i am -399 on the other side it still triggers, how can you set a range in an expression, like

(self.posistionx) -60 to 0

i guess i can add another expression so i have one saying greater than -60 and another saying less than 0
but was curious if there was a cleaner way, thanks

Best Answer

  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    The magnitude function can give you the absolute distance between the two objects.

    Use something like the following expression:
    magnitude( self.Position.X - game.actor2PositionX , self.Position.Y - game.actor2PositionY )

    You can create a game attribute to store actor2's X and Y position.

Answers

  • rhinokeyrhinokey Member Posts: 158
    hmm well it seems using the 2 expressions made stuff glitch out i think its because they contradict themselves
  • rhinokeyrhinokey Member Posts: 158
    oh snap @RThurman bassed on your suggestion i looked up a tshirtbooth tute where he talks about magnitude, and i do believe i can make this work. thanks!
Sign In or Register to comment.