Problem with collision

gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
edited November -1 in Working with GS (Mac)
Putting Boto and the Isms aside for the while, I've decided on another game that I'll stick with. It's a fairly major project, which will include some so-called mini-games. One of these will be a sliding blocks puzzle.

Trying out a test for the last few days, sliding works OK (with a reservation), but collision is not good at all.

Here are the rules I'm using for one of the blocks that can slide left or right:

Rule
When touch is pressed
Change Attribute self.DragandDrop to true
Otherwise
Change Attribute self.DragandDrop to false

Rule
When self.DragandDrop is true
Constrain Attribute self.Position.x to game.Mouse.Position.x

Rule
When Actor overlaps or collides with actor of type: wall
Change Attribute self.DragandDrop to false

• It all sort of works. The reservation I have, or problem as well, I guess, is when the user presses/clicks on the block, the block jumps to the mouse/touch x position. Of course, that's what I've put in the Rules to happen. What I really need is for the block to be dragged from any point within the block without this initial jump, if you see what I mean. some maths is needed on the lines of:

Constrain Attribute self.Position.x to --(psedocode) -- the mouse/touch position minus the difference between the mouse/touch point and the block position. I've tried to do this but it won't let me.

• the second problem is the block stopping on collision with a wall, as well as another block, eventually. It does stop, but with not much refinement, i.e it sometimes travels a bit through into the wall, and if the block is swiped quite hard, will travel all the way through. (I can't use the Collide Behaviour because this causes a bounce, which I don't want). I'm wondering if there's some nifty Rules to make a clean collision/clean stop with the block and the wall.

If anyone could solve these two probs I'd be most grateful; i'd whoop as well! Thanks.

""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    I'll bump this post if that's OK but fearing the worst: no one can help me here. Ah well, another idea of mine bites the dust.

    :-(

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I think FMG has a drag and drop demo that will work. Check his wall.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    There's some excellent demos/templates on FMG's page for sure; nothing that can help unfortunately, but thanks anyway.

    I'll go back to experimenting with the Collision Behavior, to see if I can tweak that to what I need. Cheers.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    I've come to the conclusion that dragging and collision don't "talk to each other" as such in GS. If anyone knows any different it'd be great to know, thank you.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JackBQuickJackBQuick Member Posts: 524
    This is something that might help you on the first problem you listed above:

    Dragging without snapping to the touch x and y

    With regards to your problem of the block stopping at a wall, could you make the wall unmovable (in the actor's attributes: Movable under Physics -- I think that the default is movable and you have to uncheck it)?
  • JackBQuickJackBQuick Member Posts: 524
    After making the wall unmovable, you should be able to use the Collide behaviour without creating any bounce.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thanks for pointing me in the right direction Dennis; appreciated. I must have missed that one when going through Joe's templates! His solution with the offset is excellent as usual. It certainly solves the dragging without initial jumping problem.

    Still leaves the collide when dragging prob. Thanks also for your suggestion to use the collision behavior but I tried that early on, and it doesn't seem to work properly at all when the user is dragging the object.

    Anyone any ideas about this please?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • firemaplegamesfiremaplegames Member Posts: 3,211
    @gyroscope:

    Constraining something to the mouse takes precedence and overrides all collisions.

    I am pretty sure that you will need to accomplish this with logic, not the physics engine.

    You will need to use similar logic to a volume slider, which relies on the min() and max() functions, like this:

    Rule
    When Touch is Pressed
    .....Change Attribute self.dragging To: true
    otherwise
    .....Change Attribute self.dragging To: false

    Rule
    When self.dragging = true
    -----Constrain Attribute: self.Position.X To: max(self.leftLimit,min(self.rightLimit,mouse.Position.X))

    So the above code will allow you to slide an actor back and forth between the leftLimit and rightLimit.
    Now, you will need to do something similar. You will also need to move up and down with similar logic.

    If you are making a standard 15-piece puzzle, there will only be one open space at a time. So you will only be able to move a piece one space - either left/right, or up/down.

    So you will need to determine, through logic, whether the piece can move horizontally or vertically, and what its left, right, upper, and lower limits will be.

    Without arrays, this becomes an exercise in tedium, but I believe it can be accomplished.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    firemaplegames said:

    Constraining something to the mouse takes precedence and overrides all collisions.

    I am pretty sure that you will need to accomplish this with logic, not the physics engine.

    Thanks for confirming what I thought here, Joe.
    firemaplegames said:

    You will need to use similar logic to a volume slider, which relies on the min() and max() functions, like this:

    Rule
    --------etc
    max(self.leftLimit,min(self.rightLimit,mouse.Position.X))

    Wow, truly impressed with that! Can't get my head around it as to how it works,(i.e no y values required; the min being in the place of where the y coordinate should go, etc.,) but it sure works! Excellent stuff.

    I did consider using maximums and minimums (though I would never have got the above algorythm in a month of Sundays); though thought that finding all of the max's and mins when concerning the possible positions of the other blocks would be a lot of work. You confirmed that nicely as well:
    firemaplegames said:
    If you are making a standard 15-piece puzzle, there will only be one open space at a time. So you will only be able to move a piece one space - either left/right, or up/down.

    So you will need to determine, through logic, whether the piece can move horizontally or vertically, and what its left, right, upper, and lower limits will be.

    Without arrays, this becomes an exercise in tedium, but I believe it can be accomplished.

    As you mentioned the one open space at a time: I wonder if there might be a way to determine a free space on a grid system, which would allow the block to move; if the grid space was filled with another block, then not? My head's spinning with that one but could be something there to work with...but as you imply, even that without arrays might be difficult/lot of work.

    If only Moveable could be turned on and off, that would help a long way, do you think?

    Thank you very much for your help, Joe, much appreciated.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JackBQuickJackBQuick Member Posts: 524
    gyroscope said:
    As you mentioned the one open space at a time: I wonder if there might be a way to determine a free space on a grid system, which would allow the block to move; if the grid space was filled with another block, then not?

    Give this a try:

    Move to an empty space (demo)

    Cheers!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    that's great Jack!
  • JackBQuickJackBQuick Member Posts: 524
    Thanks, Joe!

    @gyroscope - You might also want to take a look at netdzynr's demo here:

    [TIP] A Way To Create A Grid Based Game

    in order to see how he keeps track of occupied slots. You might want to use a version of this to judge whether the player has completed the puzzle correctly.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    JackBQuick said:
    Give this a try:

    Move to an empty space (demo)

    Cheers!

    Terrific stuff Jack, thank you very much! Excellent scripting/Ruling. I've been studying it to see if it can accomodate blocks of different widths and heights, to see it can be amended. Anyhow, excellent; appreciated.

    Thanks for the link as well, I'll check that out; that looks to be useful also.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JackBQuickJackBQuick Member Posts: 524
    I've updated the demo to include a method to check for correct puzzle positions:

    Move to an empty space (demo)

    The actor attributes "row" and "column" are reserved for the final position of the pieces when the puzzle has been solved. (There are two rows and three columns in the template. The bottom left piece is row 1, column 1; the one on its right is row 1, column 2, etc.)

    Also, I've used it in a small app to promote my next game update so you can see how it works in action:

    Thumbs Promo Puzzle

    Cheers!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thanks again Jack; nicely done. :-) Really like your graphics, by the way!

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JackBQuickJackBQuick Member Posts: 524
    Thanks, gyroscope!

    The cartoon characters were done by Ian (Debug Design):

    Cheap game graphics for a limited time!!!

    The rest are me playing around in Swift Publisher, Art Text, and Pixelmater.

    With regards to your question about accommodating different sized pieces: yes, it can. However, I would duplicate the puzzle piece actor for each shape, change the distance being measured, and create a global offset attribute to add to the distance moved.

    I've got everything in my head but I'm working on a bunch of different things right now. I'll either throw a demo up later today or later this week.

    All the best.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Ah yes, Ian's work is terrific!
    JackBQuick said:

    With regards to your question about accommodating different sized pieces: yes, it can. However, I would duplicate the puzzle piece actor for each shape, change the distance being measured, and create a global offset attribute to add to the distance moved.

    I've got everything in my head but I'm working on a bunch of different things right now. I'll either throw a demo up later today or later this week.

    All the best.

    That sounds beyond my expertise at the moment; if you get the time to get a demo together, that'd be really appreciated, thanks!

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JackBQuickJackBQuick Member Posts: 524
    Here it is:

    Move to an empty space with long pieces (demo)

    Good luck with your project!
  • JackBQuickJackBQuick Member Posts: 524
    Whoops, I goofed -- I was working too fast, and not testing enough. There were some timing issues and sometimes, the longer pieces went where they shouldn't.

    They've been corrected now.
  • JackBQuickJackBQuick Member Posts: 524
    I've made it into a fully functioning mini game now:

    Move to an empty space with long pieces (demo)

    Enjoy.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thank you Jack, that is excellent and cleverly done; very much appreciated. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • JoeMeisterJoeMeister Member Posts: 602
    gyroscope said:
    Terrific stuff Jack, thank you very much! Excellent scripting/Ruling. I've been studying it to see if it can accomodate blocks of different widths and heights, to see it can be amended. Anyhow, excellent; appreciated.

    Thanks for the link as well, I'll check that out; that looks to be useful also.

    :-)

    Need Help!!!
    This template is super. Copied it and studied it and copied everything into my game. (this will be a mini game in my new game)
    But I can't get it to work. Getting up at 4 in the morning for the last couple of days trying to find my mistake.
    I would like to e-mail my copy to you to look it over, maybe you can tell me what I did wrong.
    Again great template...love it....would like to get it to work.
    Please help.

Sign In or Register to comment.