Hey so im trying to recreate a controller like this miniclip game >>
how would i go about making something like this. Currently what im trying to do is having a rectangle a parent of a pivot and i move it around depending on where the user swipes. So far i managed to get it working to fall and rise up again but when its flat on the ground and you try to move it sideways it gets really complicated to code. I feel like i might be doing it in a wrong way hence why its getting complicated.
If I were you, I do this using a separate move-helper gameobject. When you move in a direction you place this move-helper at the point on the ground along the edge over which you’re turning with its forward vector in the direction you’re moving and up vector in the global up direction. Then parent your block to it, rotate the helper parent along its X-axis from 0 to 90 degrees before unparenting it again to finish the move.
Here is an example of this process from this editor:
Step 1:
Block and move helper are unparented.
Step 2:
Place move helper along movement edge, rotate to point in direction of movement with up as global up.
Rotate your helper around its x axis from 0-90. Since we rotated it so that forward looks in the direction we’re moving and up is the global up before we parented it, this should be the same for any movement direction.
There are still some complications such as where to place the move helper. When you make a move, you should still be storing your block’s position(s) on the grid so that at any point you know the position of the ground is around the block and you know when it’s fallen off the edge, stepped on a switch, etc. I say positions because when it’s on its side it will take up 2 cells. If you haven’t used it so far, look into unity’s gizmos (Unity - Scripting API: Gizmos) to maintain visual in-scene debugging information! It’s so much more useful to be able to look in the scene and see some coloured cubes showing where you might place your move helper than logging various vectors to the console.
Hope this helps, let me know if you have any problems