# Arm rotation for walking animation

• ### Question

• ` GraphicsWindow.Title= "NARUTO RPG"  GraphicsWindow.BackgroundColor = "SkyBlue"  GraphicsWindow.Width = 600  GraphicsWindow.Height=400  GraphicsWindow.CanResize = "False"    GraphicsWindow.DrawLine(0, 300, 600, 300)  head = Shapes.AddEllipse(20, 20)  headpoint["x"] = 20  headpoint["y"] = 220  Shapes.Move(head,headpoint["x"], headpoint["y"])  GraphicsWindow.BrushColor = "Red"  leftarm = Shapes.addRectangle(10, 30)  GraphicsWindow.BrushColor = "White"  torso = Shapes.AddRectangle(10, 30)  GraphicsWindow.BrushColor = "Blue"  rightarm = Shapes.AddRectangle(10, 30)  Shapes.Move(leftarm,  headpoint["x"]+5, headpoint["y"] +20)  Shapes.Move(torso, headpoint["x"]+5, headpoint["y"] +20)  Shapes.Move(rightarm,  headpoint["x"]+5, headpoint["y"] +20)  GraphicsWindow.BrushColor = "Red"  leftleg = Shapes.AddRectangle(10, 30)  GraphicsWindow.BrushColor = "Blue"  rightleg = Shapes.AddRectangle(10, 30)  Shapes.Move(rightleg,headpoint["x"]+5, headpoint["y"] +50 )  Shapes.Move(leftleg,headpoint["x"]+5, headpoint["y"] +50 )  direction = -1  GraphicsWindow.KeyDown = walking  GraphicsWindow.KeyUp = standing  Sub walking    keypressed = GraphicsWindow.LastKey        If keypressed = "D" Then    headpoint["x"] = headpoint["x"] +1   ElseIf keypressed = "A" then    headpoint["x"] = headpoint["x"] -1    EndIf    Shapes.Move(head,headpoint["x"], headpoint["y"])        angle = angle + (deltaarm*2)    displacement = angle/5    direction = direction    TextWindow.WriteLine(angle)    If direction = -1 Then      deltaarm = 1      If angle > 45 Then        direction = 1       EndIf    ElseIf direction = 1 then      deltaarm = -1      If angle < -45 then        direction = -1      EndIf      EndIf    Shapes.Rotate(leftarm, angle)    Shapes.Rotate(rightarm, -angle)    Shapes.Rotate(leftleg, -angle)    Shapes.Rotate(rightleg, angle)        Shapes.Move(leftarm,  headpoint["x"]+5-displacement, headpoint["y"] +20)      Shapes.Move(torso, headpoint["x"]+5, headpoint["y"] +20)  Shapes.Move(rightarm,  headpoint["x"]+5+displacement, headpoint["y"] +20)      Shapes.Move(rightleg,headpoint["x"]+5-displacement, headpoint["y"] +50 )  Shapes.Move(leftleg,headpoint["x"]+5+displacement, headpoint["y"] +50 )endsubSub standing'  angle = 0   Shapes.Rotate(leftarm, angle)  Shapes.Rotate(rightarm, angle)  Shapes.Rotate(leftleg, angle)  Shapes.Rotate(rightleg, angle)   Shapes.Move(leftarm,  headpoint["x"]+5, headpoint["y"] +20)      Shapes.Move(torso, headpoint["x"]+5, headpoint["y"] +20)  Shapes.Move(rightarm,  headpoint["x"]+5, headpoint["y"] +20)      Shapes.Move(rightleg,headpoint["x"]+5, headpoint["y"] +50 )  Shapes.Move(leftleg,headpoint["x"]+5, headpoint["y"] +50 )  endsub`
I am trying to make a walking animation. is there a way to make it better?

• Edited by Wednesday, November 11, 2015 5:30 PM Updated Again, fixed displacement
Wednesday, November 11, 2015 5:12 PM

• Marked as answer by Wednesday, December 9, 2015 9:11 PM
Wednesday, November 11, 2015 7:20 PM
• your wanlking man is quite effective and code looks good, maybe extend by adding a jump and running, or a second player or other animated shapes, maybe a bird with flapping wings.

Perhaps a subroutine for each type of movement, then call the appropriate subroutine when a certain key is pressed.

Also you could comment the code a bit and maybe use a subroutine to initialise everything.

Wednesday, November 11, 2015 7:37 PM

### All replies

• Marked as answer by Wednesday, December 9, 2015 9:11 PM
Wednesday, November 11, 2015 7:20 PM
• well i want to not use pcitures

more like shape manipulation.

Wednesday, November 11, 2015 7:26 PM
• your wanlking man is quite effective and code looks good, maybe extend by adding a jump and running, or a second player or other animated shapes, maybe a bird with flapping wings.

Perhaps a subroutine for each type of movement, then call the appropriate subroutine when a certain key is pressed.

Also you could comment the code a bit and maybe use a subroutine to initialise everything.

Wednesday, November 11, 2015 7:37 PM
• running might be a bit different cuz (ikr) i would be making the arms go back and teh legs more tilted and kinda just moving the legs from back to center not moving forward. heres the code commented. Btw this is for a game im making.
```GraphicsWindow.Title= "NARUTO RPG"
GraphicsWindow.BackgroundColor = "SkyBlue"
GraphicsWindow.Width = 600
GraphicsWindow.Height=400
GraphicsWindow.CanResize = "False"

GraphicsWindow.DrawLine(0, 300, 600, 300)
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.BrushColor = "White"
GraphicsWindow.BrushColor = "Blue"
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.BrushColor = "Blue"
direction = -1
GraphicsWindow.KeyDown = walking
GraphicsWindow.KeyUp = standing
Sub walking
keypressed = GraphicsWindow.LastKey

If keypressed = "D" Then ' headpoint is the "center" point, everything else follows the head.

Else
EndIf
ElseIf keypressed = "A" then

Else

EndIf
EndIf

angle = angle + (deltaarm*7) ' angle change for arms and legs
displacementx = angle/5 ' horizontal chage for arms and legs
displacementy = math.Abs(angle/9) ' vertical change for arms and legs
displacementforhead = (angle/300) ' vertical change for entire body
direction = direction

If direction = -1 Then ' direction of arms, -1 means their arms are moving back.
deltaarm = 1
If angle > 60 Then
direction = 1
EndIf
ElseIf direction = 1 then ' arms moving forward. this cam be applied to the legs as well.
deltaarm = -1
If angle < -60 then
direction = -1
EndIf
EndIf
Shapes.Rotate(leftarm, angle)
Shapes.Rotate(rightarm, -angle)
Shapes.Rotate(leftleg, -angle)
Shapes.Rotate(rightleg, angle)

endsub
Sub standing'
angle = 0
Shapes.Rotate(leftarm, angle)
Shapes.Rotate(rightarm, angle)
Shapes.Rotate(leftleg, angle)
Shapes.Rotate(rightleg, angle)