i just subscribed you and became your 500th subscriber. Congrats on 500 subs. i have one doubt. when i drag the hexagon object over sqaure object then im having object overlapping issue. to avoid object overlapping could you suggest something or make a turorial on it? that would a great help. thank you
@FirnoxGames Жыл бұрын
Thank-you so much for being my 500th subscriber. To say I didn't spend the day checking would be lying :) This is a bit tricky, normally people instantiate all their objects with different z or sort order to ensure they are never at the same level, which can mean the renderer is not sure which to do. This works for dragging, when you pick up an object you just set the value to make sure it's on top of everything. The question is what to do when you drop it. If you return it to it's original value then it could end up beneath the object you've just put it on, that wouldn't have the overlapping issue, but it's also not great. The simplest solution to this is to retain the z/sort order of the current top piece then when you drop set it to be above that (and update the top) that will always mean when you put a piece down it'll be above the others.
@AnotherWorld-r5z9 ай бұрын
How to implement this to your jigsaw puzzle series?
@AnotherWorld-r5z9 ай бұрын
i tried to add this to puzzle game, but now its not detecting clicks on puzzle selection on the grid, please help
@FirnoxGames9 ай бұрын
This video uses sprites, so I got the bounds of the sprite using the bounds on the SpriteRendere. However in the Jigsaw puzzle I created the pieces using Textures so it doesn't work as a direct copy/paste. However, it is straightforward to add all you need to do is change the dragging code within the update section. As before we get the screen bounds (same as this video). Then to limit the movement, we already have the piece sizes in the global width and height variables, we just need to scale them with respect to the gameholder (same as when we scattered the pieces) and divide by two to get half the width. Then we use clamp as in this video to limit the movement. Hope this helps: // Set the dragged piece position to the position of the mouse. if (draggingPiece) { Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); //newPosition.z = draggingPiece.position.z; newPosition += offset; // Find the screen bounds in world coordinates. Vector3 topRight = Camera.main.ViewportToWorldPoint(Vector3.one); Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(Vector3.zero); // Limit to the screen float halfWidth = width * gameHolder.localScale.x / 2; float halfHeight = height * gameHolder.localScale.y / 2; newPosition.x = Mathf.Clamp(newPosition.x, bottomLeft.x + halfWidth, topRight.x - halfWidth); newPosition.y = Mathf.Clamp(newPosition.y, bottomLeft.y + halfHeight, topRight.y - halfHeight); draggingPiece.position = newPosition; }