Collision checking different properties on each side of a square.

0 favourites
  • 12 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Dear all,

    I have multiple square sprites, and on each side of each square there is a different letter (or it could also be that there is just one type of letter for all four sides, or a combination). There are 4 letters in total.

    I would like the player to be able to drag and drop a square next to other squares, and if at least one of the sides of the newly placed square has a matching letter with its surrounding squares, it can be placed (variable: "matching" = 1). If there is no match at all, then not (variable: "matching" = 0).

    I have been struggling for a month trying to achieve this with collision checks using instances, families, UID picking, containers etc. I've read probably all topics regarding this kind of question. However, I am about to become desperate about this matter because until now I have had no results.

    Before I share some ideas of a beginning solution, I will give your creativity the freedom to suggest something potential.

    Hoping for some suggestions from you!

    Kind regards

  • I would mock something up in a test project.. a very basic example of what you are trying to do. You will definitely get more help that way.

    you don't want to go the collision route for detecting matches. I would use instance variables

    sqaure.top = "A"
    square.bot = "B"
    square.lft = "C"
    square.rgt = "D"
    
    

    use collisions for when the two squares collide, and I assume you have some sort of grid to line up the squares. The grid could be numbered so you know the location of each square.

    then once that's done compare the variables to tell you if there's a match.

  • Another option is to pin sprites with letters to each side of the square and compare overlapping letters. Here is a demo:

    dropbox.com/s/wz0qi2ih5hh8376/LettersOnBoxes.c3p

  • Another option is to pin sprites with letters to each side of the square and compare overlapping letters.

    Thank you very much for this example!

    What I'm struggling with right now is how to place specific letters on to specific places (so not randomised image frames). I tried it using image point names, but in setting the animation frame I can not refer to an image point's name. Do you perhaps know how I can have the "detection" letters (frames) match the static letters on the squares (pre determined)? Someone in the forum once mentioned this need before too: "It would be useful to be able to get sprite1.imagepointname(loopindex) the same way we can get the sprite1.imagepointx(loopindex) as it would save keeping another array in sync with the image points." He/she mentions solving this using an array. However, I have no idea how to do that either....

    I'm also trying to detect whenever a group of squares becomes separated (so when 2 or more groups with connected squares exist). Really not a single clue how to approach this one....

  • I'm also trying to get the actions based on the variable "letterMatch" to work, but it doesn't.

    What I'd like to do is that after each drop, the assessment: if the letters match or not, will influences the variable.

    So on drop: if "letterMatch" = 1 -> do action. If "letterMatch" = 0 -> don't do action.

  • What I'm struggling with right now is how to place specific letters on to specific places (so not randomised image frames)

    Here you go - re-download the file:

    dropbox.com/s/wz0qi2ih5hh8376/LettersOnBoxes.c3p

    If my example I'm changing the opacity when letters match, you can set a variable or do something else.

  • Wow, thank you so much Dop2000!

    It works very well. Finally my desperation ended thanks to you. Thanks!

    Yes, so talking about if letters match at overlap: what I would like at the end is that if there is no match (lettersMatch=0), the square returns to its original place. If lettersMatch=1 then the placement in the new location is ok. This assessment needs to be done each time a square is dropped.

    I have managed to do the logic on returning to original location and testing it with another kind of check and its variable, but now what I find is:

    - the placement to original place doesn't work with the lettersMatch=0 variable

    - whenever there has been a match the variable stays on 1. I have tried both global variable and object variable for lettersMatch.

    Do you have any idea about this perhaps? Sorry to bother you again. We have come so far, closing the case by reaching the functionality goal would be super!

    Thanks!

  • I don't really understand your game.. If you need to set lettersMatch variable per each box, then you need an instance variable. If you need to count successful matches, use a global variable.

    You can add a pair of instance variables startX and startY to the box, set them to box.x and box.y on start of the layout. When the box is dropped and there is no match, return its position to box.startX, box.startY

  • If you need to set lettersMatch variable per each box, then you need an instance variable.

    Indeed, so each time a box is dropped it checks if there is a match and if so, the lettersMatch instance variable becomes 1. If not, it will become/stay 0. However, I can't seem to get this to work.

    Also, after there has been a match and a new box is picked up, the lettersMatch instance variable needs to be 0 again.

    You can add a pair of instance variables startX and startY to the box, set them to box.x and box.y on start of the layout. When the box is dropped and there is no match, return its position to box.startX, box.startY

    Yes! Thank you, this one I managed hehe, but thank you anyways :)

  • Indeed, so each time a box is dropped it checks if there is a match and if so, the lettersMatch instance variable becomes 1.

    Instance variable on which box should becomes 1? The one that is dropped, or the one that has the same letter? Or both?

    Also, when you pick up a different box, it should have instance variable set to 0 by default. Instance variables have different value for each object instance.

  • I managed it!

    Just inverting the animation matching and if so, then return the box to original position.

    Thank you so much!!

    So the very last thing I'm struggling with is:

    Imagine the boxes are touching from the beginning of the layout. Then if a box is placed so that there are 2 separate groups, then the box reverts to the past position. How to detect those 2 "groups"...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure I understand.

    Try this new version, maybe it'll be of any help:

    dropbox.com/s/wz0qi2ih5hh8376/LettersOnBoxes.c3p

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