I'm not sure I understand the problem exactly, but there's a simple example,
using the logic indicated in @LuizVieira's commentary, which I believe is the
more efficient for this case (without the need to use Behaviors ):
The first object ( obj1
) follows the coordinates of the mouse, so each event tick its
position is updated according to the command:
Set position to (Mouse.X, Mouse.Y)
In this same event, I added an action that increases the size of obj1
as a function of time dt*10
(to simulate the growth of the object):
Set size to (obj1.Width + dt*10, obj1.Height + dt*10)
Since the position of object 2 ( obj2
) must follow obj1
, the position
of this object must be related to the obj1.X
and obj1.Y
properties.
To keep obj2
away from obj1
by size, a
possibility is to add the sum of these sizes to the
obj2
(in this example, only in the X
axis):
Set position to (obj1.X + obj1.Width/2 + obj2.Width/2, obj1.Y)
Simplifying the calculation of the X
position, you can eliminate a division:
Set position to (obj1.X + (obj1.Width + obj2.Width)/2, obj1.Y)
The Event sheet looks like this:
Andtheendresult:
Update(inresponsetocomment):
Theobjectobj2
(objectthatoverlaps)isconnectedtoobj1
throughbehaviorPin
.
- Onepossibilitytosolvetheproblemistoremovethebehavior
Pin
fromobj2
andupdateitsposition"manually" with the command Set position to
, whenever there is movement of obj1
(according to the answer above).
- Another possible solution is to change the position of
obj2
with behavior Pin
disabled on all actions where there are size changes of obj1
. After changing the position of obj2
, re-enable Pin
.
After applying the second suggestion in the example above, the Event sheet looks like this: