Would any kind of collision apply in this case?

2

I have two objects that move together ('pasted') on the map, both following the movement of the mouse. One of the objects grows by collecting small 'things', by doing so the other object begins to overlap the object that is growing. That's the problem.

Both objects have the behaviors: BoundToLayout + Pin + Bullet + Solid.

What do I do to prevent one object from overlapping the other?

    
asked by anonymous 27.02.2016 / 01:55

1 answer

0

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)isconnectedtoobj1throughbehaviorPin.

  • OnepossibilitytosolvetheproblemistoremovethebehaviorPinfromobj2andupdateitsposition"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:

    
29.02.2016 / 07:48