Answered by:
Arm rotation for walking animation
Question

GraphicsWindow.Title= "NARUTO RPG"
I am trying to make a walking animation. is there a way to make it better?
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"]+5displacement, 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"]+5displacement, headpoint["y"] +50 )
Shapes.Move(leftleg,headpoint["x"]+5+displacement, headpoint["y"] +50 )
endsub
Sub 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
 Edited by JetFire3201 Wednesday, November 11, 2015 5:30 PM Updated Again, fixed displacement
Wednesday, November 11, 2015 5:12 PM
Answers

Take a look here How would you animate a stick figure that is walking right
and here Challenge of the Month  July 2013
 Marked as answer by litdev Wednesday, December 9, 2015 9:11 PM
Wednesday, November 11, 2015 7:20 PMAnswerer 
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.
 Proposed as answer by Ed Price  MSFTMicrosoft employee Thursday, November 19, 2015 8:28 AM
 Marked as answer by litdev Wednesday, December 9, 2015 9:11 PM
Wednesday, November 11, 2015 7:37 PM
All replies

Take a look here How would you animate a stick figure that is walking right
and here Challenge of the Month  July 2013
 Marked as answer by litdev Wednesday, December 9, 2015 9:11 PM
Wednesday, November 11, 2015 7:20 PMAnswerer 
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.
 Proposed as answer by Ed Price  MSFTMicrosoft employee Thursday, November 19, 2015 8:28 AM
 Marked as answer by litdev Wednesday, December 9, 2015 9:11 PM
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) 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 is the "center" point, everything else follows the head. If headpoint["x"] > 390 Then Else headpoint["x"] = headpoint["x"] +3 EndIf ElseIf keypressed = "A" then If headpoint["x"] < 20 Then Else headpoint["x"] = headpoint["x"] 3 EndIf EndIf Shapes.Move(head,headpoint["x"], headpoint["y"]) 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) TextWindow.WriteLine(headpoint["y"]) Shapes.Move(leftarm, headpoint["x"]+5displacementx, headpoint["y"] +20  displacementy ) Shapes.Move(torso, headpoint["x"]+5, headpoint["y"] +20) Shapes.Move(rightarm, headpoint["x"]+5+displacementx, headpoint["y"] +20  displacementy) Shapes.Move(rightleg,headpoint["x"]+5displacementx, headpoint["y"] +50  displacementy) Shapes.Move(leftleg,headpoint["x"]+5+displacementx, headpoint["y"] +50  displacementy) endsub Sub 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(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
Wednesday, November 11, 2015 7:41 PM 
for jumping im not that great with physics so (i could use litdev extension) but i want to go straight code for those who may not have that extension so. and jumping might be a good idea for my traveling sequenceWednesday, November 11, 2015 7:43 PM

Hi JetFire
Don't forget to mark a reply as answered if it has answered your question.
Hey btw I posted some suggestions for motion practice in this month's challenge.
Friday, November 27, 2015 12:00 PM