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

0 favourites
  • 12 posts
From the Asset Store
Now you can drop everything in your game with sound :)
  • 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!

  • I'm sure adding Solid behaviour to both, walls and the ball, will solve your problem

  • 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...

  • bump...

  • ... 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.

  • Use my method:

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • ... 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.

    Use my method: how-do-i-set-drag-bounds-for-a-sprite_t122964?&start=10&hilit=drag

    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

  • 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

  • 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!

  • Forget drag and drop, try this way.

    https://mega.nz/#!EpE22YLb!Rn2OZ5Bi4-bVFt1_y59qt5RPSrnOIQdaIuV034HibR8

    Cheers.

  • Forget drag and drop, try this way.

    https://mega.nz/#!EpE22YLb!Rn2OZ5Bi4-bVFt1_y59qt5RPSrnOIQdaIuV034HibR8

    Cheers.

    Thanks, but it seems like a lot more work than R0J0hound's solution...

    I think I'll go with that one.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)