Would any kind of collision apply in this case?

Asked

Viewed 297 times

2

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

Both objects have the Behaviors: Boundtolayout + Pin + Bullet + Solid.

What do I do so that one object does not overlap the other?

  • 1
  • 1

    I don’t know in detail the Construct 2. But it would help if you explain what these behaviours do. Probably some of these behaviours are responsible for making the object "grow". In this case, what you can do is calculate the distance between the two objects and move away what grows from each other in proportion to how much it grows. It is more practical, more computationally efficient, and generates potentially better results than using a Colisor.

  • 1

    And as fellow @rubStackOverflow rightly said, if you provide (for download, with a link to Dropbox, for example) a minimal project example that replicates the problem, it makes it enormously easy for someone who has Construct installed to be interested in testing and helping you.

1 answer

0


I’m not sure I understand exactly the problem, but follow a very simple example, using the logic indicated in the @Luizvieira comment, 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 to each Event tick your position is updated as per command:

Set position to (Mouse.X, Mouse.Y)

At this very event, I added a 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)

As the position of object 2 (obj2) must follow the obj1, the position of this object must be related to the properties obj1.X and obj1.Y.

To maintain the obj2 away from the obj1 depending on the size, a possibility is to add the sum of these sizes to the position of the obj2 (in this example, only on the axis X):

Set position to (obj1.X + obj1.Width/2 + obj2.Width/2, obj1.Y)

Simplifying the calculation of the position X, it is possible to eliminate a division:

Set position to (obj1.X + (obj1.Width + obj2.Width)/2, obj1.Y)


The Event sheet gets that way:

Event sheet para a descição acima

And the end result:

Resultado da animação


Update (in response to comment):

The object obj2 (object superimposing) is connected to the obj1 through the behavior Pin.

  • One possibility to solve the problem is to remove the behavior Pin of obj2 and update its position "manually" with the command Set position to, whenever there is movement of obj1 (as the answer above).


  • Another possible solution is to change the position of the obj2 with the behavior Pin disabled in all actions where there are changes in the size of the obj1. After changing the position of the obj2, enable the Pin.


After applying the second suggestion in the above example, Event sheet is as follows:

Event sheet da segunda sugestão

  • Hi. Thanks for answering! I tried to use what you said, but it didn’t work... I think it’s because I use a different 'system' to make obj1 grow. Well, below I put the link to an image of the system I’m using, if you can help me apply to it what you said, I would appreciate it very much! https://3.bp.blogspot.com/-B6dzleho52s/Vtywbmxewji/Aaaaaaaaafm/Zk4kdd1uwe0/s1600/system.JPG

  • Hi! I believe I now understand the problem. The obj2 is "connected" to obj1 through the behavior Pin, that’s it?

  • Yes. Exactly.

  • I updated the answer! I hope it helps solve the problem :)

  • Hello. I tried several times, but I still can’t... Below I put the way I’m doing,e uns pequenos cometários. imagem1: https://1.bp.blogspot.com/-v-Qu2oeqoic/Vtdbnxrh21i/Aaaaaaaaafc/Ynj3q0iblqw/s1600/imagem1.JPG Original configuration, no use of Every tick, where Obj1 grows when colliding/destroying something, add to it 1 point. I then use an Instance Variable called dot1. In Obj1, I use Set Bullet of motion to Angle(Self.X, Self.Y, Mouse.X, Mouse.Y), because Set position gives an error where Obj1 and Objt2 follow the mouse very, very fast, not following the stipulated speed.

  • Imagem2: https://1.bp.blogspot.com/-nqfbvoSU2HY/Vtdblimrldi/Aaaaafg/bKYXfcRAMtU/s1600/imagem2.JPG This is the way I’m applying what you said. Instead of Obj1.Width, I’m putting Obj1.points1, since it’s this variable that makes Obj1 grow. I also took out the /2 comma, and I put a /2+ sign, because with the comma it’s giving error. Do I have to create some variable for Obj2, to put in place of . Width?

  • Saw the project, no need to create a new variable and also no need to add the event Every tick. Everywhere you find one Set size to of obj1, you can add the sequence of actions (obj2) of the example (just below this Set size): Unpin, Set position exactly the same as in example 2 (no need to put the pontos), Pinagain. By Event sheet of your project, you need to make this change in 4 places (Events 26, 27, 30 and 31). Please let me know if it worked :)

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.