Constrain spawned actor

PimanPiman Member, PRO Posts: 165
edited August 2012 in Working with GS (Mac)
I have actor 1 that spawns another actor, and I want this to be somewhere in actor one's circle radius. (Somewhere around it). When when actor 1 is moved, I want actor 2 to stay in that same place where it spawned... How can I achieve this? I have been messing around have it spawned randomly from actor 1 and then have magnitude/position constraints in actor 2 of various sorts, but I can't get it work.

Could anybody give me an example, please?

Comments

  • PimanPiman Member, PRO Posts: 165
    No one? :/
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    In Game:
    -- Make two attributes bossX and bossY (type = real)

    In Actor 1:
    -- Constrain Attribute: game.bossX To: self.Position.X
    --Constrain Attribute: game.bossY To: self.Position.Y
    --Spawn: Actor 2
    ----Position > random(-self.Size.Width /2.5, self.Size.Width /2.5)
    ----Position ^ random(-self.Size.Height /2.5, self.Size.Height /2.5)
    ----Relative To: actor

    In Actor 2: Make two attributes myOffsetX and myOffsetY (type = real), then:
    -- Change Attribute: self.myOffsetX To: self.Position.X - game.bossX
    -- Change Attribute: self.myOffsetY To: self.Position.Y - game.bossY
    -- Constrain Attribute: self.Position.X To: game.bossX + self.myOffsetX
    -- Constrain Attribute: self.Position.Y To: game.bossY + self.myOffsetY
  • PimanPiman Member, PRO Posts: 165
    Thanks, but it's not working. Actor two is supposed to spawn somewhere on the outer edge of an (invisible) circle of actor 1.
  • PimanPiman Member, PRO Posts: 165
    Wouldn't I need cos/sin for this?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @Piman -- OOPS! I misunderstood your question. I thought you were asking how keep Actor 2 somewhere within (inside) the radius of Actor 1. What you actually want is to have Actor 2 spawn directly on the "outer edge" of Actor 1's circle. In that case you would want to randomly designate an angle to spawn Actor 2 and then use the width and height of Actor 1 to determine how far Actor 2 is spawned from the center of Actor 1. That would go something like this:

    In Actor 1: (Make an attribute called newAngle. It can be type index, angle, real, or integer.
    -- Constrain Attribute: game.bossX To: self.Position.X
    -- Constrain Attribute: game.bossY To: self.Position.Y
    -- Change Attribute: self.newAngle To: random(0,359)
    -- Spawn: Actor 2
    ---- Position >: ( self.Size.Width /2)*sin( self.newAngle )
    ---- Position ^: ( self.Size.Height /2)*cos( self.newAngle )
    ---- Relative To: actor


    Note: I might have sin and cos reversed. If it acts strange, try switching them.
  • PimanPiman Member, PRO Posts: 165
    I want it to spawn in the radius of the circle, but starting from a certain distance(not too close, not too far) and then I want it to be constrained to its spawning position...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Try:
    ---- Position >: (random(10,self.Size.Width/2))*sin( self.newAngle )
    ---- Position ^: (random(10,self.Size.Height/2))*cos( self.newAngle )

    You can replace the '10' with another number. Experiment with it to get the effect you are after.
This discussion has been closed.