I’m building a game with a puzzle part, like a MasterMind,
I want the player to test color combination to find the right ones.
What is the expected result
I use the draggable behavior. I have 6 vials of color and 6 puzzle slots that are the combinations. I want, when i drop my vial to color the slot that is on.
What is the actual result
At the moment when i drop the vial, the wrong slot is colored, and i don’t reach to understand how the collision is made…
It’s hard to tell what’s going on because the movement in the gif is too fast. You appear to drop the vial onto the grey bar, yet the circle below it takes the vial. Unless I’m seeing things wrong?
Are the slots and vials on the same layer? If they’re not, have you scaled one of the layers?
As a suggestion for debugging - while dragging, highlight the slot that the vial centre is over.
And why are you tweening the vial’s scale, and then setting in the action immediately after?
Actually that is the issue, it work if i dropped the vial higher and on left, its like the bounding box of the slot is at the wrong place (despite the debug option that shows it at the right place).
Slots and vials are not on the same layer.
The layers are not scaled but place in the right position on the UI using Code
Thanks for the screen snips of the camera repositioning. It’ll be those that are causing the issue. I’ll try to explain why:
Say you have 2 50x50 square sprites on separate layers (say layer_A and layer_B), both positioned at (100,100). If you move the mouse so it’s visually over one square then it’s over the other square too. That is because both squares are in the same position - scene wise and screen wise.
If you move the camera of layer_A so it’s 100 pixels across to the left and 100 pixels up from it’s current position, then the square on layer_A will appear down 100 pixels and to the right by 100 pixels of the square on layer_B. This is layer_A square’s screen position. It’s scene position hasn’t changed - it’s still at (100, 100).
When you move the mouse to (125, 125), it will appear to be at the middle of the square on Layer_B. It is also the middle of the square on layer_A which, although it’s screen position has changed, is still at (100,100) and the mouse will be at it’s centre.
That is what’s happening with your slots - their location in the scene matches that of the grey bar, but visually is below the grey bar on the screen.
There are a couple of ways around this:
don’t move the camera on the map_tile layer. Instead move all the objects on it.
work out the positional difference between the cameras for the layer the vials are on and for the layer the slots are on, and add this difference when checking whether the point is in a slot.