Grow actor with constrained position offset.

kjflukekjfluke Member, PRO Posts: 23
edited November -1 in Working with GS (Mac)
Hi guys. I have a problem. I have an actor that grows while a certain attribute is true at a random point selected from a set of points. I need a specific point on the edge of the actor to constrain to the point of origin, so that the actor appears to grow away from the origin rather than grow from the center. One complicating factor is that the actor also spawns at a random angle.

So essentially what I need to do is constrain a point exactly half of the width (which is constantly changing) from the center position of the spawned actor, at the current angle, and x and y attribute defined by the random point selection. Uggh.

Any help?

Comments

  • Rob2Rob2 Member Posts: 2,402
    Like an inverse health bar but set at an angle ?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    One way would be a four step process. 1) set the actor's width to the distance between point a and point b, 2) set the actor's x position halfway between point a.x and point b.x, 3) set the actor's y position halfway between point a.y and point b.y, 4) set the angle.

    For example, suppose I have 2 actors whose name is "A" and "B", and I have a third actor (self) that I wanted to grow between the two. (And I was using the instances in the scene.) The behaviors would look like this:

    Change Attribute: self.Size.Width To: magnitude( scene.Background.A.Position.Y - scene.Background.B.Position.Y , scene.Background.A.Position.X - scene.Background.B.Position.X )

    Change Attribute: self.Position.X To: ( scene.Background.A.Position.X + scene.Background.B.Position.X )/2

    Change Attribute: self.Position.Y To: ( scene.Background.A.Position.Y + scene.Background.B.Position.Y )/2

    Change Attribute: self.Rotation To: vectorToAngle( scene.Background.A.Position.X - scene.Background.B.Position.X , scene.Background.A.Position.Y - scene.Background.B.Position.Y )

    Hope this helps,
    RThurman
  • theCodeMonsterstheCodeMonsters Member Posts: 359
    All you have to do is just constrain the position of the actor the the point on the map that you want him to.
    ___________________________________________________________________________
    I'm teaching an online programing course go here to find out more!!! http://gamesalad.com/forums/topic.php?id=31505
  • kjflukekjfluke Member, PRO Posts: 23
    Maybe I need to clarify. Imagine a leaf growing from a vine. The angle of the "leaf" is random. The size of the "leaf" is changing while a certain attribute is true. During that time, I would like it to appear as though it were growing from the base of the leaf rather than from the center. If there is no angle involved, it looks like this (with "origin" being the location for the spawning to begin):
    Constrain Att: self.position.x to (game.origin.x)-((self.size.width)*.5)
    with no change to y as in this case it is just a horizontal actor growing from right to left. The problem I am having is having the position change based on the same angle and making the distance between "self.position" and "origin" change proportional to 1/2 of the width of the "leaf".
    Thanks for your help!
  • kjflukekjfluke Member, PRO Posts: 23
    Health bar! yes just like that! but at a random angle.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- that clarifies things a bit:

    Change Attribute: self.Rotation To: random(-90,270)
    Constrain Attribute: self.Position.X To: game.origin.x+(( self.Size.Width *.5)*cos( self.Rotation ))
    Constrain Attribute: self.Position.Y To: game.origin.y+(( self.Size.Width *.5)*sin( self.Rotation ))

    Then you can 'grow' self.Size.Width however you want.

    Also, the 'leaf' does not 'grow' left or right because of the addition sign. It grows to the left or right depending on the angle. So angles between 91 and 270 grow it to the left. And angles between 89 and -90 grow it to the right.

    Hope that helps
    RThurman
  • kjflukekjfluke Member, PRO Posts: 23
    Thanks! I'll give it a shot!
  • kjflukekjfluke Member, PRO Posts: 23
    RThurman! That worked smashingly! Thanks!
  • kjflukekjfluke Member, PRO Posts: 23
    now if I can just figure out a multitouch rotations system...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    There might be a more efficient way, but as far as I can tell, that takes about 10-12 "change attributes" and two or three "rules". But it is doable.
Sign In or Register to comment.