(S) How do I stop drag and drop trough walls.

Get help using Construct 2

Post » Wed Apr 26, 2017 12:07 pm

Hey, I'm trying to make a game where you need to drag a ball trough a maze.

I'm using drag and drop to drag the ball, but I don't know how to stop it from going trough the walls...

I first made it drop the ball on collision with the wall, but then you can just pick it back up and go trough the wall;
Then I added the physics behaviour to both the ball and the walls and made the walls immovable so that when I drop the ball, it would get "flinged" out of the wall.

But this isn't quite what I want... I'd like to keep dragging the ball even if the mouse is over a wall, but the ball to stop at the border with the wall and to move only sideways with the mouse...

So, is there a way to get this to work?
Thanks!
Last edited by TRMG on Fri Apr 28, 2017 12:23 pm, edited 1 time in total.
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Wed Apr 26, 2017 12:48 pm

I'm sure adding Solid behaviour to both, walls and the ball, will solve your problem :)
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Wed Apr 26, 2017 1:05 pm

grigrizljac wrote:I'm sure adding Solid behaviour to both, walls and the ball, will solve your problem :)

I added it, but the ball still goes trough the walls...
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Wed Apr 26, 2017 10:26 pm

bump...
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Thu Apr 27, 2017 12:44 am

... haha i hate drag and drop too!!

too many variables to make it work perfect.

I can help to u if u upload a simple capx.

Cheers.
https://www.facebook.com/TeslaPCgames

https://www.twitter.com/TeslaPCGames

[email protected]

http://www.synergy-studios.net
B
39
S
20
G
58
Posts: 111
Reputation: 32,168

Post » Thu Apr 27, 2017 2:20 am

ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Post » Thu Apr 27, 2017 2:23 am

This is a start:

Global number x0
Global number y0
Global number x1
Global number y1

Start of layout
--- set x0 to Sprite.x
--- set y0 to Sprite.y

Every tick
--- set x1 to Sprite.x
--- set y1 to Sprite.y
--- Sprite: set position to (x0,y0)
--- Sprite: set angle towards (x1, y1)

Repeat distance(x0,y0, x1,y1) times
--- Sprite: move forward 1 pixel
------ Sprite: is overlapping wall
--------- stop loop
--------- Sprite: move forward -1 pixels

Every tick
--- set x0 to sprite.x
--- set y0 to Sprite.y



That will stop the Sprite at walls when being dragged. Having it slide against the walls is more deluxe. There are a few examples around the forum. Not exactly simple but there may be other ways.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Thu Apr 27, 2017 5:06 pm

TeslaPC wrote:... haha i hate drag and drop too!!

too many variables to make it work perfect.

I can help to u if u upload a simple capx.

Cheers.


R0J0hound wrote:This is a start:

Global number x0
Global number y0
Global number x1
Global number y1

Start of layout
--- set x0 to Sprite.x
--- set y0 to Sprite.y

Every tick
--- set x1 to Sprite.x
--- set y1 to Sprite.y
--- Sprite: set position to (x0,y0)
--- Sprite: set angle towards (x1, y1)

Repeat distance(x0,y0, x1,y1) times
--- Sprite: move forward 1 pixel
------ Sprite: is overlapping wall
--------- stop loop
--------- Sprite: move forward -1 pixels

Every tick
--- set x0 to sprite.x
--- set y0 to Sprite.y



That will stop the Sprite at walls when being dragged. Having it slide against the walls is more deluxe. There are a few examples around the forum. Not exactly simple but there may be other ways.

Oh wow, didn't expect it to be this difficult... Is there a simpler way of doing it?

Here's a capx: https://www.dropbox.com/s/6cvo3w40rdv9u ... .capx?dl=0
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Post » Thu Apr 27, 2017 6:20 pm

It doesn't get too much simpler. With Alextro's you can still drag through the walls, and it may not work well for long shapes. If you tried the code I posted it would stop at walls but would snag on them and not slide.

For sliding here are two different ways. The first moves horizontally then vertically a step at a time. Sliding works very well for unrotated walls.
https://www.dropbox.com/s/s70h5bf670edb ... .capx?dl=0
The second just pastes in the wall slide events I've used elsewhere with some other capx's. It's surprisingly modular I must say. Anyways, it requires putting an imagepoint at the corners of the walls, but the end result is smooth wall sliding.
https://www.dropbox.com/s/251tpcwb6mg0u ... .capx?dl=0
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Thu Apr 27, 2017 6:49 pm

R0J0hound wrote:It doesn't get too much simpler. With Alextro's you can still drag through the walls, and it may not work well for long shapes. If you tried the code I posted it would stop at walls but would snag on them and not slide.

For sliding here are two different ways. The first moves horizontally then vertically a step at a time. Sliding works very well for unrotated walls.
https://www.dropbox.com/s/s70h5bf670edb ... .capx?dl=0
The second just pastes in the wall slide events I've used elsewhere with some other capx's. It's surprisingly modular I must say. Anyways, it requires putting an imagepoint at the corners of the walls, but the end result is smooth wall sliding.
https://www.dropbox.com/s/251tpcwb6mg0u ... .capx?dl=0

Alight then, thanks!
ImageImageImageImage
B
28
S
9
G
7
Posts: 229
Reputation: 5,518

Next

Return to How do I....?

Who is online

Users browsing this forum: Lancifer and 15 guests