How do I do to stop dragged objects into obstacles

Get help using Construct 2

Post » Sat May 10, 2014 12:05 pm

How to make the object with Physics behaviour, stop at obstacles while being dragged (Drag and drop).

Thanks
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat May 10, 2014 1:59 pm

Please check my example on this topic. https://www.scirra.com/forum/viewtopic.php?f=147&t=103985

I believe that the same rule can apply to your needs.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Sat May 10, 2014 6:05 pm

Hi @eli0s.

It's similar, but In my case the object must continue to be dragged so I can take it to another place. In my project the object returns to the original place when I drop it.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat May 10, 2014 6:20 pm

I am sorry, I don't understand what you mean by "the object returns to the original place when I drop it". I thought that you want upon collision for the drag&drop behavior to stop acting. The "while" events in my example ensure that there is no overlapping between the sprites, I guess that since you use the Physics Behavior that wouldn't even be necessary because the detection is very tight by it's own with physics.

Can you share a capx file to clarify your needs?
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Sun May 11, 2014 12:31 am

Hi eli0s,

I meant that the object needs to be dragged constantly, without crossing any obstacle, until reach the goal. For example, this simple CAPX that I shared, the goal is to bring the cup to the water without going through the bucket without being dropped before. From what I saw in your project, the object stops being dragged every time that touch the obstacle and I need to click again to drag it.
You do not have the required permissions to view the files attached to this post.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sun May 11, 2014 12:26 pm

So, what happens when the object touches the orange frame? It resets its position at the startx, starty coordinates?

Nevertheless, what you really need is a "Pick" action, as opposed to the "Drop" that the Drag&Drop behavior already has. That way you would drop the object every time it overlaps and pick it up again automatically if the mouse were still pressed.

To be honest, I can't think of something useful. The closest I got is without using the Drag&Drop behavior, with a simple "set position to" mouse.X, mouse.Y action (you can lerp it for smoother movement) and a boolean that becomes false when the object overlaps with the container and stops the "set position" action. The problem is that when it stops the overlapping and we re-enable the "set position", the result is a jagged movement as the object collides and re-collides constantly with the container. Also, if you sweep the object fast enough, you can even pass thru the container, since the 60fps aren't enough to check for the collisions.

Sorry that I couldn't be of more help.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Sun May 11, 2014 12:33 pm

Also.. check this one: viewtopic.php?t=101511

You can save the X and Y of the object into a variable as soon as a touch event happens. When you release it you canset an action to force/impulse towards those coordinates.
B
24
S
4
G
1
Posts: 177
Reputation: 1,827

Post » Sun May 11, 2014 1:30 pm

Hi @eli0s,

eli0s wrote:So, what happens when the object touches the orange frame? It resets its position at the startx, starty coordinates?


The object just can not cross the orange sprite and must continue to be dragged without release the mouse button.

Nevertheless, what you really need is a "Pick" action, as opposed to the "Drop" that the Drag&Drop behavior already has. That way you would drop the object every time it overlaps and pick it up again automatically if the mouse were still pressed.


This solution seems to be interesting. Could you make an example using CAPX that I have shared?

To be honest, I can't think of something useful. The closest I got is without using the Drag&Drop behavior, with a simple "set position to" mouse.X, mouse.Y action (you can lerp it for smoother movement) and a boolean that becomes false when the object overlaps with the container and stops the "set position" action. The problem is that when it stops the overlapping and we re-enable the "set position", the result is a jagged movement as the object collides and re-collides constantly with the container. Also, if you sweep the object fast enough, you can even pass thru the container, since the 60fps aren't enough to check for the collisions.


It's true. I tested it and didn't work.
Last edited by RBuster on Sun May 11, 2014 1:35 pm, edited 2 times in total.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sun May 11, 2014 1:33 pm

Hi @henriquesv

I tested this action and didn't work for me. If you can, please, use my CAPX to show your solution. Thanks.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sun May 11, 2014 2:51 pm

RenatoB wrote:This solution seems to be interesting. Could you make an example using CAPX that I have shared?


Unfortunately, such an action doesn't exist. I've stated the lack of it on this topic (https://www.scirra.com/forum/viewtopic.php?f=146&t=104264) which criticize the lack of controlling some behavior parameters thru actions. I don't rate this need as high enough though, I doubt that Ashley will prioritize this any time soon.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests