Problem with collision
gyroscope
I am here.Member, Sous Chef, PRO Posts: 6,598
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.
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
:-(
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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)?
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
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.
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: 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
Move to an empty space (demo)
Cheers!
@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.
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
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!
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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.
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Move to an empty space with long pieces (demo)
Good luck with your project!
They've been corrected now.
Move to an empty space with long pieces (demo)
Enjoy.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps