# Difficult collision problem

Get help using Construct 2

### » Thu Dec 13, 2012 8:50 pm

Hello everyone, I prevent a perplexing problem.

Let's say I have two click-and drag nodes, with a bar that always extends between them. A simple matter to program.

The nodes can be dragged around the layout at will and the bar will always extend between them (simple programming).

Now, in the context of this arrangement, there will be some walls/obstacles in the layout.

How can I program the arrangement so that the user can never position the system so that any object (nodes or bar) intersects any wall?

Here's a capx of the example. It's pretty simple as I haven't implemented any sort of collision prevention.

https://dl.dropbox.com/u/41931267/Linkage.capx

So, what do you think I should do? I thought of using physics, but that brings problems with clicking and dragging...

Thanks!
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,749

### » Fri Dec 14, 2012 8:31 pm

*Bump*

I got pushed off the front page very quickly. Any of you brains out there able to lend some assistance?
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,749

### » Sat Dec 15, 2012 1:42 am

YOu could make both solid objects, so they don't intersect

https://dl.dropbox.com/u/108799982/Capx%20Demos/Draggy.capx

If that's not suitable, can you upload a .capx of what you have ?
Using R248 for all examples
B
70
S
21
G
6
Posts: 382
Reputation: 9,812

### » Sat Dec 15, 2012 1:48 am

The simplest manner would be to have something like two lines, one that is updated if the line does not overlap anything, then another line at 50% opacity that is placed between the two points every time.

Aside from that, I'm not sure what you want to do. Have it be pushed out? Have it be rotated out? Only update the position of each point if the line is not overlapping anything?
Moderator
B
96
S
34
G
33
Posts: 3,006
Reputation: 27,931

### » Sat Dec 15, 2012 2:02 am

The easiest solution is just to change the opacity, or tint it red, or use some other visual indication to mean "invalid".
Scirra Founder
B
415
S
248
G
92
Posts: 25,295
Reputation: 200,994

### » Sat Dec 15, 2012 2:21 am

@Ashley I know exactly what you mean, and that idea occurred to me. I might end up using that, actually.

@Arima I sort of want to block the user from making the pipe go inside the wall, while leaving the motion open in other directions.sqiddster2012-12-15 02:21:27
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,749

### » Sat Dec 15, 2012 9:42 am

One idea would be to not drag the nodes directly but rather drag ghost nodes. When you drop the ghost it moves back to the node. While dragging you could then do a loop to move the nodes to the ghosts in steps. Each step reposition the bar and if it collides with the box move the node in the opposite direction from the ghost a bit.

Or something like that.
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Sat Dec 15, 2012 1:26 pm

Hmm, not a bad idea, lots to think about ;)
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,749

Return to How do I....?

### Who is online

Users browsing this forum: No registered users and 9 guests