Hi all,
I'm working on a project where a parent object creates children which are its physics. Each child is 16x16 and I loop through the image data of the parent to create their offsets. However, I canot seem to make these children align with their parent's rotation properly at all. I'd rather not hard code any of the rotations so that if I were to add other objects to rotate that it would be universal and easy to deal with.
Attached is the .love file of the game currently.
Creating physics based on image rotation
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Creating physics based on image rotation
- Attachments
-
- Senior Project.love
- (48.82 KiB) Downloaded 207 times
Re: Creating physics based on image rotation
I don't quite understand your post, but based on the .love file you have,
will assume that you're asking "why isn't the L shape rotating like in the classic Tetris".
One simple thing I would suggest - instead of manually rotating each piece in realtime using math,
just pre-generate all possible rotations and swap them when a key is pressed.
will assume that you're asking "why isn't the L shape rotating like in the classic Tetris".
One simple thing I would suggest - instead of manually rotating each piece in realtime using math,
just pre-generate all possible rotations and swap them when a key is pressed.
Re: Creating physics based on image rotation
It seems to me that your problem is the pivot point for the rotation. Is that right?
If so, you probably want to find the centre of the bounding box to use it as the rotation's pivot. In the cases where the bounding box's centre lies on the middle of an edge (which for tetrominoes, is in all cases except the 2x2) you will need first to extend the bounding box so that all sides have the same parity (all odd or all even).
Let me elaborate.
If so, you probably want to find the centre of the bounding box to use it as the rotation's pivot. In the cases where the bounding box's centre lies on the middle of an edge (which for tetrominoes, is in all cases except the 2x2) you will need first to extend the bounding box so that all sides have the same parity (all odd or all even).
Let me elaborate.
- The bounding box of the "T", the "L" and the "S" tetrominoes is 2x3. 2 and 3 have different parity (2 is even and 3 is odd). In such cases, rotating around the bounding box's centre causes the rotated figure to be misaligned with the grid. That can be corrected by extending the bounding box to be either 2x4 (not recommended) or 3x3 (recommended), so that both dimensions have the same parity.
- Similarly, the "I" tetromino's bounding box is 1x4, and since 1 and 4 have different parity, you need to correct that by extending the bounding box to either 2x4 (not recommended) or 1x5 (recommended), so that both are the same parity.
- The square tetromino is 2x2; since 2 and 2 have the same parity (both even), no adjustment is necessary for that one.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 12 guests