Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if UnitDefs[Spring.GetUnitDefID(unitID)].name == "armcom" then
- base, lthigh, rthigh, rleg, lleg, lfoot, rfoot,ruparm, luparm, torso = piece ("pelvis", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot","ruparm", "luparm","torso")
- piecetable = {
- thighs = {
- r = {
- length = 20,
- },
- l = {
- length = 20,
- },
- },
- legs = {
- r = {
- length = 20,
- },
- l = {
- length = 20,
- },
- },
- foots = {
- r = {
- length = 5,
- },
- l = {
- length = 5,
- },
- },
- }
- wantedstepfrequency = 0.5
- elseif UnitDefs[Spring.GetUnitDefID(unitID)].name == "armpw" then
- base, lthigh, rthigh, rleg, lleg, lfoot, rfoot,ruparm, luparm, torso = piece ("pelvis", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot","ruparm", "luparm","torso")
- piecetable = {
- thighs = {
- r = {
- length = 0.8,
- },
- l = {
- length = 0.8,
- },
- },
- legs = {
- r = {
- length = 3,
- },
- l = {
- length = 3,
- },
- },
- foots = {
- r = {
- length = 3,
- },
- l = {
- length = 3,
- },
- },
- }
- wantedstepfrequency = 1.5
- elseif UnitDefs[Spring.GetUnitDefID(unitID)].name == "armbanth" then
- base, lthigh, rthigh, rleg, lleg, lfoot, rfoot = piece ("hips", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot")
- piecetable = {
- thighs = {
- r = {
- length = 7.64,
- },
- l = {
- length = 7.64,
- },
- },
- legs = {
- r = {
- length = 13,
- },
- l = {
- length = 13,
- },
- },
- foots = {
- r = {
- length = 0,
- },
- l = {
- length = 0,
- },
- },
- }
- wantedstepfrequency = 1
- end
- local SIG_WALK = 2
- local PlaySoundFile = Spring.PlaySoundFile
- local GetUnitPosition = Spring.GetUnitPosition
- local GetGameFrame = Spring.GetGameFrame
- common = include("headers/common_includes_lus.lua")
- piecest = {base, lthigh, rthigh, rleg, lleg, lfoot, rfoot}
- Step = {}
- Step[1] = {}
- Step[2] = {}
- Step[3] = {}
- function ProcessWalkParams()
- while (true) do
- realstepfrequency = ((UnitDefs[Spring.GetUnitDefID(unitID)].speed/((Speed+0.01) * 30))/10 + 0.9)*wantedstepfrequency
- Spring.Echo((UnitDefs[Spring.GetUnitDefID(unitID)].speed/((Speed+0.01) * 30))/10 + 0.9)
- --thighs
- AnimationTime = 1/realstepfrequency
- Step[1].animationtime = AnimationTime/3
- Step[2].animationtime = AnimationTime/3
- Step[3].animationtime = AnimationTime/3
- StepLength = Speed * 30 * AnimationTime
- wholeleglength = piecetable.thighs.l.length + piecetable.legs.l.length + piecetable.foots.l.length
- halfleglegnth = piecetable.legs.l.length + piecetable.foots.l.length
- footlength = piecetable.foots.l.length
- thighfullangle = math.atan(StepLength/wholeleglength)
- thighfrontangle = -thighfullangle/2
- thighbackangle = thighfullangle/2
- pelvisangle = thighfrontangle/4
- uparmfrontangle = thighfrontangle
- uparmbackangle = thighbackangle
- torsofrontangle = thighbackangle/4
- Sleep(10)
- end
- end
- function GetAngleValues(angle,speed)
- return newangle, newspeed
- end
- function GetIsTerrainWater()
- x,y,z = Spring.GetUnitPosition(unitID)
- if Spring.GetGroundHeight(x,z)<= -8 then
- return true
- else
- return false
- end
- end
- function Emit(pieceName, effectName)
- local x,y,z,dx,dy,dz = Spring.GetUnitPiecePosDir(unitID, pieceName)
- dx, dy, dz = 1, 0, 1
- Spring.SpawnCEG(effectName, x,y,z, dx, dy, dz)
- end
- function UnitTurns()
- t = 0
- heading = {}
- while (true) do
- difference = 0
- heading[t] = Spring.GetUnitHeading(unitID)
- if heading[t-1] then
- if heading[t-1] ~= heading[t] then
- difference = heading[t] - heading[t-1]
- else
- difference = 0
- end
- if math.abs(difference * 8 * 360 / 65536) <= 15 then
- difference = 0
- end
- difference = difference * 8 * 360 / 65536
- if difference > 50 then
- difference = 50
- elseif difference < -50 then
- difference = -50
- end
- if difference ~= 0 then
- -- Spring.Echo("turning")
- -- Spring.Echo(difference)
- end
- if heading[t-2] then
- heading[t-2] = nil
- end
- difference = difference + randomness/10
- end
- t = t+1
- Sleep (1)
- end
- end
- function GetSurroundingTerrain(frontfoot)
- x,y,z = Spring.GetUnitPosition(unitID)
- dx, dy, dz = Spring.GetUnitDirection(unitID)
- GroundHeightUnderFoot = Spring.GetGroundHeight(x+8*dx, z+8*dz)
- GroundHeightUnderCom = Spring.GetGroundHeight(x, z)
- HeightDifference = GroundHeightUnderFoot - GroundHeightUnderCom
- if HeightDifference <= 0 then
- AdditiveAngle = -math.abs(math.atan(HeightDifference/math.sqrt(64*dx^2+64*dz^2)))*(300/currentSpeed)* 1/0.0174533 * 1/2
- else
- AdditiveAngle = math.abs(math.atan(HeightDifference/math.sqrt(64*dx^2+64*dz^2)))*(300/currentSpeed)* 1/0.0174533 * 1/2
- end
- if y < 0 then
- if y < -35 then
- y = -35
- end
- AdditiveAngle = AdditiveAngle*2
- end
- -- Spring.Echo(AdditiveAngle)
- if AdditiveAngle <= 0 or randomness*0.1 + AdditiveAngle <= 0 then
- AdditiveAngle = (AdditiveAngle + randomness*0.1)/2
- else
- AdditiveAngle = AdditiveAngle + randomness*0.1
- end
- -- Spring.Echo(AdditiveAngle)
- return AdditiveAngle
- end
- function walk()
- if moving then
- if not (alreadystartedmoving) then -- leftleg to front, from stopped to move
- Turn (lthigh, 1, thighfrontangle, thighfrontangle/Step[1].animationtime)
- Turn (rthigh, 1, thighbackangle, thighbackangle/Step[1].animationtime)
- Turn (base, 2, pelvisangle, pelvisangle/Step[1].animationtime)
- Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[1].animationtime)
- Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[1].animationtime)
- Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
- Move (base, 3, 1, 1/Step[1].animationtime)
- Turn (lleg, 1, 0, thighfrontangle/Step[1].animationtime)
- Turn (rleg, 1, thighbackangle, thighbackangle/Step[1].animationtime)
- alreadystartedmoving = true
- Sleep(Step[1].animationtime * 1000)
- end
- end
- if moving then -- Default
- Turn (lthigh, 1, 0, thighfrontangle/Step[2].animationtime)
- Turn (rthigh, 1, 0, thighbackangle/Step[2].animationtime)
- Turn (base, 2, 0, pelvisangle/Step[2].animationtime)
- Turn (luparm, 1, 0, uparmbackangle/Step[2].animationtime)
- Turn (ruparm, 1, 0, uparmfrontangle/Step[2].animationtime)
- Turn (torso, 1, 0, torsofrontangle/Step[2].animationtime)
- Move (base, 3, 0, 2/Step[1].animationtime)
- Turn (lleg, 1, 0, thighfrontangle/Step[2].animationtime)
- Turn (rleg, 1, thighbackangle, thighbackangle/Step[2].animationtime)
- Sleep(Step[2].animationtime * 1000)
- end
- if moving then -- Rightleg to front
- Turn (lthigh, 1, thighbackangle, thighbackangle/Step[3].animationtime)
- Turn (rthigh, 1, thighfrontangle, thighfrontangle/Step[3].animationtime)
- Turn (base, 2, -pelvisangle, pelvisangle/Step[3].animationtime)
- Turn (ruparm, 1, uparmbackangle, uparmbackangle/Step[3].animationtime)
- Turn (luparm, 1, uparmfrontangle, uparmfrontangle/Step[3].animationtime)
- Turn (torso, 1, torsofrontangle, torsofrontangle/Step[3].animationtime)
- Move (base, 3, 2, 2/Step[3].animationtime)
- Turn (lleg, 1, thighbackangle, thighbackangle/Step[3].animationtime)
- Turn (rleg, 1, 0, thighfrontangle/Step[3].animationtime)
- Sleep(Step[3].animationtime * 1000)
- end
- if moving then--lleg to front from not moving to moving
- if not (alreadystartedmoving) then
- Turn (rthigh, 1, thighfrontangle, thighfrontangle/Step[1].animationtime)
- Turn (lthigh, 1, thighbackangle, thighbackangle/Step[1].animationtime)
- Turn (base, 2, pelvisangle, pelvisangle/Step[1].animationtime)
- Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[1].animationtime)
- Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[1].animationtime)
- Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
- Move (base, 3, 1, 1/Step[1].animationtime)
- Turn (rleg, 1, 0, thighfrontangle/Step[1].animationtime)
- Turn (lleg, 1, thighbackangle, thighbackangle/Step[1].animationtime)
- alreadystartedmoving = true
- Sleep(Step[1].animationtime * 1000)
- end
- end
- if moving then -- default pos
- Turn (rthigh, 1, 0, thighfrontangle/Step[2].animationtime)
- Turn (lthigh, 1, 0, thighbackangle/Step[2].animationtime)
- Turn (base, 2, 0, pelvisangle/Step[2].animationtime)
- Turn (luparm, 1, 0, uparmfrontangle/Step[2].animationtime)
- Turn (ruparm, 1, 0, uparmbackangle/Step[2].animationtime)
- Turn (torso, 1, 0, torsofrontangle/Step[1].animationtime)
- Move (base, 3, 0, 2/Step[2].animationtime)
- Turn (rleg, 1, 0, thighfrontangle/Step[2].animationtime)
- Turn (lleg, 1, thighbackangle, thighbackangle/Step[2].animationtime)
- Sleep(Step[2].animationtime * 1000)
- end
- if moving then -- left leg to front
- Turn (rthigh, 1, thighbackangle, thighbackangle/Step[3].animationtime)
- Turn (lthigh, 1, thighfrontangle, thighfrontangle/Step[3].animationtime)
- Turn (base, 2, pelvisangle, pelvisangle/Step[3].animationtime)
- Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[3].animationtime)
- Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[3].animationtime)
- Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
- Move (base, 3, 2, 2/Step[3].animationtime)
- Turn (rleg, 1, thighbackangle, thighbackangle/Step[3].animationtime)
- Turn (lleg, 1, 0, thighfrontangle/Step[3].animationtime)
- Sleep(Step[3].animationtime * 1000)
- end
- end
- function walklegs()
- end
- function stopwalk()
- end
- function UnitSpeed()
- vx,vy,vz,Speed = Spring.GetUnitVelocity(unitID)
- while (true) do
- vx,vy,vz,Speed = Spring.GetUnitVelocity(unitID)
- currentSpeed = Speed*100*60/moveSpeed
- if (currentSpeed < 100) then currentSpeed = 100 end
- randomness = math.random(-25,25)
- currentSpeed = currentSpeed + randomness
- Sleep (1)
- end
- end
- function MotionControl()
- justmoved = true
- while (true) do
- if (moving) then
- dgunning = 0
- if (aiming) then
- walklegs()
- else
- walk()
- end
- justmoved = true
- else
- if( justmoved ) then
- -- Move (pelvis, 2, 0)
- if side == 0 then
- else
- end
- if not (aiming) then
- end
- justmoved = false
- end
- Sleep (100)
- end
- Sleep (1)
- end
- end
- function script.Create()
- side = math.random(0,1)
- randomness = math.random(-25,25)
- addheight = 0
- moving = false
- aiming = false
- building = false
- justfired = false
- dgunning = false
- buildy = 0
- buildx = 0
- moveSpeed = UnitDefs[Spring.GetUnitDefID(unitID)].speed
- currentSpeed = 100
- Spring.UnitScript.StartThread(MotionControl)
- Spring.UnitScript.StartThread(UnitSpeed)
- Spring.UnitScript.StartThread(UnitTurns)
- Spring.UnitScript.StartThread(ProcessWalkParams)
- -- Spring.SetUnitNanoPieces(unitID, {lfirept})
- end
- function script.StartMoving()
- building = false
- moving = true
- dgunning = false
- end
- function script.StopMoving()
- moving = false
- end
- function script.Killed()
- for count, piece in pairs(piecest) do
- Explode(piece, SFX.EXPLODE_ON_HIT)
- Hide(piece)
- end
- return 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement