What you describe sounds like the most basic and simple example of
"Inverse Kinematics" - which basically means determining how you would
arrange the parts of a system like a jointed body so that the end
points (like say hands and feet) satisfy some set of criteria. Inverse
Kinematics is a very google-searchable topic.
But speaking to pygame and your simple example specifically - the two
functions of interest are probably math.atan2 and
pygame.transform.rotozoom, and they would let you figure out the angle
the arm should be at, and draw the arm image rotated, respectively.
Here's like some non-working incomplete code that should give the idea:
angle = math.atan2(mouse.x - shoulder.x, mouse.y - shoulder.y)
rotated_arm = pygame.transform.rotozoom(arm_image, angle, 1.0)
display.blit(rotated_arm, (shoulder.x, shoulder.y))
the ugly stuff I glossed over is how you get the arm image so that it
lines up with the shoulder right, cause rotozoom returns an image that
is bigger than the original, and I forget exactly how to deal with it.
The archives for this list have various cases of people asking about
how to use rotozoom, with helpful explanations.
On 9/15/07, Lamonte Harris <pyth0nc0d3r@xxxxxxxxx> wrote:
Basically lets give a real live example. When your standing up and you move
your arm at an diagonal the socket of the bone doesn't move but your arm
does, lets put this back to pygame. How would Say if K have a simple sprite
that has 2 parts body,1 arm. How would say if that sprite is in the middle
of the screen don't move but when I move the mouse the arm points in the
direction of where the mouse is located, but doesn't exactly move to that
position, how would that exactly work?