From Sonic Retro
The Giant Mech is the final boss of Sonic the Hedgehog 2. It is a huge robot made in the likeness of Dr. Eggman. This boss returns as a final boss again in Sonic 4's E.G.G Station Zone, and once again as a boss in Sonic Generations, now called the Death Egg Robot.
The robot will take four steps toward you, half a step back, then launch off the screen. You have to jump and hit him, but the robot has two spiked fists about halfway up his body. Touching these or his legs will kill you and force you to fight Mecha Sonic again. Sonic must jump and hit him above the spiked fists. This is very difficult to do at any time, but the safest times to do it are when he is standing still and not taking a step. Hitting the bot when it is walking is considerably more risky, although it's the only way to win the battle quickly. The safest time to hit him is when he bends down slightly (This happens at two points, when he stands still a moment before he launches and right after he appears or lands). Don't hit him when he takes his last step forward since one of his fists will be extended forward.
After he launches, a white target circle appears on you and follows Sonic wherever you go. When a smaller circle appears inside the larger one, it means the target has locked on, and won't follow you. This is the time to move. The robot will come down where the target locked on.
He will then shoot both fists at you, one at a time. The fists don't fly all the way across the room. Eggman will, after launching his fists, launch again, and repeat the last step with the target and try to land on you. After that the entire sequence will repeat.
If you get behind Eggman at any time when he lands, he'll stay stationary and launch two mines at you. The mines fall where you were standing when they launched and explode shortly after they land. Robotnik is not as vulnerable from behind as he is from the front so this is to your disadvantage. After shooting the mines, he will launch upward again.
After defeating the second boss, Sonic runs off the edge of the exploding Death Egg, ending the level and leading to the Sonic 2 ending animation.
Playing as Knuckles
The peak of his jump puts him horizontally level with the spiked fists. This means you can only hit above the arms when the robot is bending down. It is possible to score hits under the arms using glide but this requires timing and precision almost impossible to keep up. Avoid the temptation to hit the robot when it is walking, as you will die.
When hitting the robot when it is bending down, it is possible to pass through the outline of the robot chest and die upon contact with the arms. To avoid this, always pull back as soon as contact with the chest has been made.