Need Help Stoping an object being moved by touch control

0 favourites
  • 7 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have set up a game where you drag a character around the screen with your finger using touch controls. I need walls to stop the movement of the character (like if he was going through a maze) but for the life of me I cannot figure out a way to do this. I'm new to using this program and so much of the collision detection in this engine seems to be set up with using Solids and then a movement behavior. But I can't seem to find any behavior combination that would allow a touch controlled object to collide with a solid like all the other control schemes do.

    I've been using Game Salad for the past few years and they have simple collision detection. If an object collides with another object you can just set it to bounce and if neither object have any bounciness, it will just stop moving. But since I can't seem to find any bounce like events in this engine when using touch, I'm totally stumped.

    All I want is a way to stop the sprite's movement like it does using any of the other control types. I've tried using a set position command to make the object manually bounce back a bit if it collides, but it looks really janky and doesn't always work right especially if I try to use a small movement number. I'm sure someone must have built a game using this type of control scheme before but I just can't seem to find any examples of it in the manual or in the tutorials.

    Any help that can be provided would be greatly appreciated.

  • Add a condition to your logic that says "If Overlapping Wall" or whatever your wall objects are called, and then invert that condition so it says basically "Not if Overlapping Wall".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • BluePhaze:

    Thanks for responding back so quickly. That's a good suggestion but it doesn't work quite right. The touch object will overlap the collision and the rule basically says "Hey don't let touch work if overlapping." which on the surface sounds great. The problem is, the object is always overlapping at that point and so the rule is always in effect and you can never move your object again. I could add in a bit of manual bounce back to shove it away from the wall object so it's not overlapping but then I'm right back to it looking janky again.

    And unfortunately the "on collision" event doesn't want to seem to give me an Invert option so it's overlap or nothing.

    Any other suggestions?

  • Let the touch work separate , it's the actual drag/move logic for the item being dragged that should use the "Not overlapping" logic. Unless I am picturing it wrong in my mind...

  • BluePhaze:

    I guess I should have made this more clear. I'm controlling a sprite using the Touch control. To move the sprite I'm saying:

    If TOUCH is touching "Player" then set position of "Player" to Touch X and Touch Y.

    This is how I've done it in the past on other engines and assumed it was the proper way to do that here. I'm not using the Drag and Drop behaviors (though I suppose I could try using those).

    Anyway, using your suggestion I have to add the inverted collision conditions into that rule so it knows that the object can be moved as long as its not colliding. Therefore the rule now says

    If TOUCH is touching "Player"

    and if

    "Player" is NOT overlapping "Wall"

    then

    set position of "Player" to Touch X and Touch Y.

    but going this route won't work because like I said, as soon as the object overlaps, the rule goes into effect and stays in effect because nothing is stopping the Player from overlapping the collision creating an endless loop.

    There isn't another place to put the NOT command because it has to be with the initial touch control. Does this make more sense? Maybe I'm just not understanding you correctly...

  • Anyone else have any other suggestions for this?

    What I ended up doing for now is a variation of what was suggested and just did an invert of the touch event touching the collision. So if user is touching the player sprite but not touching the collision it can move.

    It works, but still not perfectly because you can end up dragging your finger off the sprite when it runs into collision and stops moving. I still can't believe there is no simple built in bounce collision stuff for touch controlled objects like there is for other control schemes.

  • i think custom movement has something that called push out of solid, combining that with a boolean, isdragging,

    on player touch start , set boolean, isdragging to true,

    on touch end, set bool to false

    if player.isdragging, set position player to touch position

    then using the push out of solid should keep the object from staying in overlap (in theory)

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