I have a 20 small elements, which the player needs to click, drag, and move to another position and stay where it is when the player releases the mouse click. I’m developing for iPad, so it would be best if the user could click and drag multiple elements at a time. It would also be great if the elements wouldn’t bump into each other. They need to freely slide around.
I’ve tried searching for solutions, watched all the Youtube tutorials that come up with relevant searches, but each one I find just isn’t quite the same as what I’m doing, so they don’t work. I’m working with 2D elements only.
You would have to detect if an element has been clicked, for instance with raycast or overlapcircle. Then, until there is a mouseup event, the position of the element that had been selected in the previous step should be set to the position of the mouse.
At least, that’s how I’m doing it.
Rostam24 - Maybe I’m just not experienced enough to know what to do/where to put your code example, but I tried several different things and got errors all over the place. I couldn’t get it to compile. But I would love to try to get this to work. It looks like it solves the collider issue?
orb - This worked like a charm! I love it, thank you! This will work great! Not too worried about the lack of colliders, that will just be bonus points if I can get something working in the future I guess.
orb - I just solved the collider issue! I just put a box collider 2D on the elements. Then I put a Rigid body 2D, then I set the Gravity scale to 0. This works very nicely. It makes it possible to bump the elements into other ones and even move the ones which get hit.
Yep, I think doing something more advanced than pushing things around probably needs a hefty script that checks directions and colliders. I thought it would be automatically handled by the engine with proper colliders