Constrain spawned actor
Piman
Member, PRO Posts: 165
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?
Could anybody give me an example, please?
This discussion has been closed.
Comments
-- 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
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.
---- 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.