Page 1 of 1

Animating 5 Legs

Posted: 22 Nov 2010, 20:04
by kalda341
I'm sure you are all tired of posts like these, but as far as I can tell there is no tutorial on animating with lua. How would I go about making a walking animation for something like in the attached pic? The legs are separate objects and labeled leg1 to leg5.

Re: Animating 5 Legs

Posted: 22 Nov 2010, 20:07
by oksnoop2
Sweet virus. I don't know about the 5th leg but here's ct's trusty 4 legged animation. Just add more legs?

http://code.google.com/p/conflictterra/ ... .lua?r=673

Re: Animating 5 Legs

Posted: 22 Nov 2010, 21:00
by kalda341
oksnoop2 wrote:Sweet virus. I don't know about the 5th leg but here's ct's trusty 4 legged animation. Just add more legs?

http://code.google.com/p/conflictterra/ ... .lua?r=673
The 4 legged one is looking good with it after removing all references to shins. What would I change in this script to speed up the animation?

Re: Animating 5 Legs

Posted: 22 Nov 2010, 21:05
by SanadaUjiosan

Code: Select all

                        Turn( forrthigh, x_axis, 0, 0.5 )
The 0.5 dictates speed in that line. As for the rate, I can't give you anything useful other than to play around with it.

http://springrts.com/wiki/Animation-LuaCallouts

That's a good resource if you haven't found it already.

Re: Animating 5 Legs

Posted: 22 Nov 2010, 21:54
by kalda341
Can anyone see why sb is not moving?

Code: Select all

-- by KR
       
        --pieces
        local body = piece "base"

        local baclthigh = piece "leg2thigh"
        local baclshin = piece "leg2"

        local bacrthigh = piece "leg3thigh"
        local bacrshin = piece "leg3"

        local flare1 = piece "build"

        local forlthigh = piece "leg4thigh"
        local forlshin = piece "leg4"

        local forrthigh = piece "leg5thigh"
        local forrshin = piece "leg5"

		local sa = piece "leg1thigh"
        local sb = piece "leg1"
		
        --signals
        local SIG_AIM = 1
        local SIG_AIM_SEC = 5
        local walk_go = 4
        local walk_stop = 8
local SIG_AIM = 5
local SIG_BUILD = 4

function script.Create(unitID)
end

function script.StartBuilding(heading, pitch)
        Signal(SIG_BUILD)
        SetSignalMask(SIG_BUILD)
        Turn(body, y_axis, heading, math.rad(90))
        WaitForTurn(body, y_axis)
        SetUnitValue(COB.INBUILDSTANCE, 1)
        return 1
end
function script.Querybody() return flare1 end
function script.AimFromWeapon() return body end

function script.StopBuilding()
   Signal(SIG_BUILD)
   SetSignalMask(SIG_BUILD)
   SetUnitValue(COB.INBUILDSTANCE, 0)
   Turn(body, y_axis, 0, math.rad(90))
   WaitForTurn(body, y_axis)
   Sleep(1)
   return 0
end
function script.AimFromWeapon() return flare1 end

function script.QueryWeapon() return flare1 end

function script.Queryflare1Piece() return flare1 end

function script.Killed(recentDamage, maxHealth)
   return 0
end
       
        function script.Create()
               
        end
       
        local function RestoreAfterDelay(unitID)
                Sleep(5500)
                Turn(body, y_axis, 0, math.rad(150))

        end

        local function Walk()
                SetSignalMask( walk_go )
                Sleep(30)
                while ( true ) do
                        Turn( forrshin, x_axis, 5, 5 )
                        Turn( baclshin, x_axis, -5, 5 )
						Turn( sb, x_axis, -5, 5 )
						
                        Turn( forlshin, x_axis, 0, 5 )
                        Turn( bacrshin, x_axis, 0, 5 )
						Turn( sb, x_axis, 0, 5 )

                        WaitForTurn( bacrshin, x_axis )
                        WaitForTurn( forlshin, x_axis )
                        WaitForTurn( forrshin, x_axis )
                        WaitForTurn( baclshin, x_axis )
						WaitForTurn( sb, x_axis )
                        Sleep(30)
                       

                        Turn( forlshin, x_axis, 5, 5 )
                        Turn( bacrshin, x_axis, -5, 5 )
						Turn( sb, x_axis, -5, 5 )

                        Turn( forrshin, x_axis, 0, 5 )
                        Turn( baclshin, x_axis, 0, 5 )
						Turn( sb, x_axis, 0, 5 )

                        WaitForTurn( bacrshin, x_axis )
                        WaitForTurn( forlshin, x_axis )
                        WaitForTurn( forrshin, x_axis )
                        WaitForTurn( baclshin, x_axis )
						WaitForTurn( sb, x_axis )
                        Sleep(30)
                end
        end
       
        local function StopWalk()
                Signal( walk_go )
                Turn( forrshin, x_axis, 0, 5 )
                Turn( baclshin, x_axis, 0, 5 )
				Turn( sb, x_axis, 0, 5 )
               
                Turn( forlshin, x_axis, 0, 5 )
                Turn( bacrshin, x_axis, 0, 5 )
				Turn( sb, x_axis, 0, 5 )
        end
       
        function script.StartMoving()
                StartThread( Walk )
        end
       
        function script.StopMoving()
                StartThread( StopWalk )
        end
       

        function script.QueryWeapon1() return flare1 end
       
        function script.AimFromWeapon1() return body end
       
        function script.AimWeapon1( heading, pitch )
                Signal(SIG_AIM)
                SetSignalMask(SIG_AIM)
                Turn(body, y_axis, heading, math.rad(150))
                Turn(body, x_axis, -pitch, math.rad(100))
                WaitForTurn(body, y_axis)
                WaitForTurn(body, x_axis)
                StartThread(RestoreAfterDelay)
                return true
        end
       


       
        function script.FireWeapon1()
               Sleep(30)
        end



       
        function script.Killed(recentDamage, maxHealth)
                Sleep(30)
        end

Re: Animating 5 Legs

Posted: 22 Nov 2010, 22:26
by FLOZi
Please use the [code][/code] tag.