How do I Stop on Collision

0 favourites
  • 12 posts
From the Asset Store
Perfect Particles
$2 USD
80% off
Particles support animations, collisions, effects and etc.
  • I am building a game like "unblock me", I have tried to use the Solid, Collision, 8 direction methods but can't seem to get the blocks(sprite) that are moving horizontal and vertical to stop before they collide. Can anyone point me in the right direction on how to make a sprite stop once it has encountered another object.

    Thanks

  • Can you provide a capx?

  • hey thanks... the idea is for the blocks to stop once they collide and stay in the same place, what happens is that either block starts to shift to the sides... they should stay in the path. This is a plain version I've started over with the basic sprites..

    Tony

  • This is a way to do it with two blocks. I am afraid though that when you will add more blocks the logic will be much more complicated, you have to figure out a way to do proper picking of which block is neighboring which, and that is way over my abilities.

    Maybe arrays will be the right way to approach this, but, as I never get bored to mention in every occasion I get, I don't understand arrays...

  • Using events that disable the drag and drop behavior of the object, stops the object. But it'll also make it immovable afterwards. So you have to add events that will re-enable the drag and drop again.

    Not sure if this will work but try this anyways.

    Make an event where the conditions are

    -Gold bar is above the brick bar(that is gold.Y is less than brick.Y as Y decreases as you go up)

    -Brick is overlapping gold(brick comes in contact with gold, similar to collision)

    Make an action where it disables brick drag and drop.

    Now this will stop the brick in it's tracks but you'll notice you cant move it anymore.

    Now this might only work if you have preview over lan to your phone cause you'll have to use the touch objects accelerometer option. By seeing if you swipe up or down you'll get positive or negative values for the accelerometer value.

    So say if you swipe up you get a negative Y accelerometer value (i'm not sure if it's negative or posotive, you'll have to find it out) So what you can do is add the condition(to the one i already mentioned) 'touch Y accelerometer value is less than 0 i.e negative. So now if it works it'll still disable movement if you swipe up and the gold is above brick

    Now to reenable movement , you make another action where conditions are

    -Gold above brick or Gold is not right below brick

    -Brick is overlapping gold ( if it is already overlapping )

    -touch Y accelerometer is greater than zero i.e positive

    And the event is, enable drag and drop for brick

    So now if this method actually works, when you swipe down and the gold bar is not below the brick, it should re-enable movement.

    Touch accelerometer does not work on desktop. So i'm not sure if this will work at all. Sorry

    Obviously putting Gold above brick conditions is not the only one, if the gold is to the far right and the brick is to the far left , it'll still disable movement even tho gold is not right above brick, so you have to add other conditions like comparing distance between the two.

    Please look around the tutorials, search for keywords, cause there will definitely be a more simpler and working answer.

  • thanks to both of you for your help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • pandy ? do you have a capx file ?

  • how about not going outside the box ??

  • nikkdj

    This thread is over 3 years old - the OP was resolved a long time ago.

  • zenox98

    do you have a copy of a solution ? or example ? capx?

  • eli0s i am having a problem , i tried your events , but it is not working , it is not dragging ? why ?

  • eli0s i am having a problem , i tried your events , but it is not working , it is not dragging ? why ?

    nikkdj, I'm sorry, this is a very old example and, to be honest, I don't think it's the right approach for this kind of game. Grid based movement should probably be made with arrays, or an other system that stores the position of each block and allows movement according to the vacancy/state of each cell in the grid.

    I don't really use Construct any more so I can't be very helpful. However, If you post your capx file here, perhaps me or someone more clever can tell you why the blocks are not dragging.

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