Make actors grow / shrink according to distance from any given point?

LoadedLoaded Member Posts: 240
edited September 2013 in Working with GS (Mac)
I need to try and resize an actor from 15 to 40 (width and height) over any given distance from another actor (emitter), I would like to avoid using interpolate and so far have the actor resizing using magnitude...

magnitude(self.Position.X-emitter.Position.X,self.Position.Y-emitter.Position.Y)

This is great (Thanks @RThurman ) but I want the actor to grow from size 15 to size 40 during its journey from the emitter to it's final position. It's worth noting that the final position is a random(x,y).

Anyone got any ideas? :)

Thanks, Loaded.

Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

Comments

  • LoadedLoaded Member Posts: 240
    My illogical brain is thinking that the logic I need is the magnitude between emitter and final position and the magnitude between 15 and 40, then smush them together into one expression to unite the kingdoms!!!

    Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

    Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited September 2013
    @Loaded -- There are probably several different ways to do this. Here are two;

    1) you could use the min and max functions

    max(15,min(40,magnitude( game.emitterX - self.Position.X , game.emitterY - self.Position.Y )))


    2) or you could use a formula that wont go below 15 but will keep the actor growing so that it reaches 40 when it is about a screen length from the emitter

    15+magnitude( game.emitterX - self.Position.X , game.emitterY - self.Position.Y )*.05

    The ".05" is a multiplier that you can mess with till you get the growth rate you want.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited September 2013
    Oops... just realized you want to sent the actor to a random location.

    In that case, the first thing you will need to do is get the initial distance between the actor and its final position:
    Change Attribute: self.InitialDistance To: magnitude(self.finalX - self.Position.X , self.finalY - self.Position.Y)


    Then the size formula would look something like:
    Constrain Attribute: self.size.width To: 15+(self.InitialDistance - magnitude(self.finalX - self.Position.X , self.finalY - self.Position.Y ))*((40-15)/self.InitialDistance )
  • LoadedLoaded Member Posts: 240
    Only just got around to playing with your answer @RThurman

    Works perfectly, thanks :)

    Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

    Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

  • maRaidermaRaider Member Posts: 2
    I am trying a variant of this that is not working and am unsure why. I am trying to get an object to scale based on how close to a point the player is. (This is a gravity meter that is supposed to grow as you approach the target object) I am attempting to set up a formula that puts the magnitude in a min/max formula in the denominator

    But when I do this, the object does not draw at all.

    It appears and scales (inverse to how I want it to) when there is no additional math involved, but as soon as I try to modify that magnitude calculation with any other calculations, it just stops working entirely.

    Suggestions welcome. This is a polish feature, and not crisis-worthy, but I would really like to know why it is not working.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    When it stops working entirely, it often means there is an error in the expression. It might be missing some need parentheses, or perhaps a function was typed in (instead of using the function menu), or perhaps a comma is missing.

    What are you doing when you "try to modify that magnitude calculation"?
Sign In or Register to comment.