Hi.
Yes, another scripted TF2 sketch in the works, and apparently having troubles when relying on the physics engine.
The code below is one of 3 files (b) used to run this little animation, focusing mostly on the Engineer. There is a timer loop "keephead" made to keep the Engineer's head in place and look in a particular direction. The angle is determined by ceheadang, and changes every now and then. Sometimes his head will turn to face the new direction given, and sometimes not, and it is different each time I run the code (lua_openscript). I've done prints and they seem to tell me that the ceheadang and GetAngles() match, yet visibly the head doesn't change its orientation. I've marked the places where ceheadang change with a *.
All 3 files can be downloaded at [url]http://www.edwardleuf.org/Source/gmodlua/exp8.zip[/url]
[code]
ceheadang = Angle(0,0,0)
eheadang = Angle(0,0,0)
function Engi_Posing()
for i = 0,engi:GetPhysicsObjectCount()-1 do
engi:GetPhysicsObjectNum(i):EnableGravity(false)
engi:GetPhysicsObjectNum(i):EnableMotion(true)
end
engi:SetFlexWeight(6,1)
engi:GetPhysicsObjectNum(8):EnableMotion(false)
engi:GetPhysicsObjectNum(13):EnableGravity(true)
engi:GetPhysicsObjectNum(16):EnableGravity(true)
engi:GetPhysicsObjectNum(4):EnableGravity(true)
engi:GetPhysicsObjectNum(7):EnableGravity(true)
local eheadpos = engi:GetPhysicsObjectNum(15):GetPos()
eheadang = engi:GetPhysicsObjectNum(15):GetAngles() + Angle(0,18,0)
ceheadang = eheadang
table.insert(timerIDs,"keephead")
> timer.Create("keephead",0.001,0,function()
engi:GetPhysicsObjectNum(15):SetPos(eheadpos)
engi:GetPhysicsObjectNum(15):SetAngles(ceheadang)
end)
local bkpos = bklines:GetPos()
if(math.Rand(0,1)>0.5) then
x = -1
else
x = 1
end
if(math.Rand(0,1)>0.5) then
y = -1
else
y = 1
end
local shove = Vector(x,0,y)*25000
local spin = Vector(0,0,math.Rand(-1,1))
local cR=0
local cG=0
local cB=0
local a=0
local b=0
local c=0
table.insert(timerIDs,"flybackdrop")
timer.Create("flybackdrop",1/30,0,function()
bklinesphys:ApplyForceCenter(shove)
bklinesphys:AddAngleVelocity(spin)
shove = (bkpos-bklines:GetPos())*10
if(bklinesphys:GetAngleVelocity().z>math.Rand(50,75)) then
spin = Vector(0,0,math.Rand(-0.1,-0.25))
elseif(bklinesphys:GetAngleVelocity().z<math.Rand(-50,-75)) then
spin = Vector(0,0,math.Rand(0.1,0.25))
end
if cR < 1 then
cR = 1
a = 0
elseif cR > 254 then
cR = 254
a = 0
end
if cG < 1 then
cG = 1
b = 0
elseif cG > 254 then
cG = 254
b = 0
end
if cB < 1 then
cB = 1
c = 0
elseif cB > 254 then
cB = 254
c = 0
end
if cR == 254 && cG == 1 && cB == 1 then
a = 0
b = 1
c = 0
elseif cR == 254 && cG == 254 && cB == 1 then
a = -1
b = 0
c = 0
elseif cR == 1 && cG == 254 && cB == 1 then
a = 0
b = 0
c = 1
elseif cR == 1 && cG == 254 && cB == 254 then
a = 0
b = -1
c = 0
elseif cR == 1 && cG == 1 && cB == 254 then
a = 1
b = 0
c = 0
elseif cR == 254 && cG == 1 && cB == 254 then
a = 0
b = 0
c = -1
else
if a == 0 && b == 0 && c == 0 then
a = math.ceil(math.Rand(-10,10))
b = math.ceil(math.Rand(-10,10))
c = math.ceil(math.Rand(-10,10))
end
end
cR = cR + a
cG = cG + b
cB = cB + c
bklines:SetColor(Color(cR,cG,cB,255))
end)
end
function Engi_ScreenOn()
discreen:EmitSound("items/suitchargeok1.wav")
discreen:SetMaterial("models/shadertest/shader4")
table.insert(timerIDs,"screen_flicker")
timer.Create("screen_flicker",0.35,1,function()
table.insert(timerIDs,"scrflic")
timer.Create("scrflic",0.001,0,function()
discreen:SetAngles(Angle(math.Rand(-90,90),0,0))
end)
end)
table.insert(timerIDs,"screen_on")
timer.Create("screen_on",1.4,1,function()
timer.Remove("scrflic")
discreen:SetAngles(Angle(0,0,0))
discreen:SetMaterial("models/rendertarget")
table.insert(timerIDs,"engilaugh")
timer.Create("engilaugh",0.5,1,Engi_heh)
table.insert(timerIDs,"cam5")
timer.Create("cam5",1.5,1,Spy_GlanceWhat)
end)
end
function Engi_heh()
local elaugh = CreateSound(discreen,"vo/engineer_laughshort04.mp3")
elaugh:Play()
table.insert(timerIDs,"startlaugh")
timer.Create("startlaugh",0.15,1,function()
engi:SetFlexWeight(40,0.5)
print("Head Change Engi_heh")
* ceheadang = eheadang + Angle(10,0,-15)
end)
table.insert(timerIDs,"stoplaugh")
timer.Create("stoplaugh",0.5,1,function()
print("Head Change Engi_heh")
* ceheadang = eheadang
engi:SetFlexWeight(40,0)
end)
table.insert(timerIDs,"stoplaugh2")
timer.Create("stoplaugh2",0.75,1,function()
elaugh:Stop()
end)
end
function Engi_LookUp()
print("Head Change Engi_LookUp")
* ceheadang = eheadang + Angle(10,30,-15)
table.insert(timerIDs,"donttest_speak")
timer.Create("donttest_speak",0.5,1,function()
discreen:EmitSound("vo/engineer_dominationsoldier03.mp3")
table.insert(timerIDs,"donttest1")
timer.Create("donttest1",0.05,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest2")
timer.Create("donttest2",0.3,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest3")
timer.Create("donttest3",0.6,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest4")
timer.Create("donttest4",0.9,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest5")
timer.Create("donttest5",1.05,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest6")
timer.Create("donttest6",1.3,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6 && i!=40) then
engi:SetFlexWeight(i,math.Rand(-0.25,0.25))
end
end
Engi_JawTalk()
end)
table.insert(timerIDs,"donttest7")
timer.Create("donttest7",1.8,1,function()
for i = 0,engi:GetFlexNum()-1 do
if(i!=6) then
engi:SetFlexWeight(i,0)
end
end
table.insert(timerIDs,"spyshowsap0")
timer.Create("spyshowsap0",0.5,1,Spy_ShowSap)
end)
end)
end
function Engi_JawTalk()
local move=0
timer.Remove("jaw")
timer.Remove("jaw2")
table.insert(timerIDs,"jaw")
timer.Create("jaw",1/30,8,function()
engi:SetFlexWeight(40,move)
move=move+(1/8)
end)
table.insert(timerIDs,"jaw2")
timer.Create("jaw2",0.125,1,function()
timer.Remove("jaw")
timer.Create("jaw",1/30,8,function()
engi:SetFlexWeight(40,move)
move=move-(1/8)
if(move<0) then move=0 end
end)
end)
end
function Engi_CreateBat()
timer.Remove("engbatSND")
timer.Remove("engbatSPR")
batent,batphys = Make_PhysObject("models/weapons/w_models/w_bat.mdl",dispenser:GetPos()+Vector(0,12,60),Angle(0,0,90))
batphys:EnableMotion(false)
dispenser:EmitSound("buttons/lever4.wav")
local r=90
local z=58
table.insert(timerIDs,"spinbat")
timer.Create("spinbat",1/30,5,function()
batent:SetPos(dispenser:GetPos()+Vector(0,12,z));
batent:SetAngles(Angle(0,0,r))
r=r-45
z=z-1
end)
table.insert(timerIDs,"spygasp0")
timer.Create("spygasp0",0.5,1,function()
player.GetByID(1):SetViewEntity(cam5)
player.GetByID(1):SetFOV(0,0)
table.insert(timerIDs,"spygasp1")
timer.Create("spygasp1",0.25,1,Spy_GaspAtBat)
end)
end
function Engi_HitBat()
local r=360
local x=0
local y=12
table.insert(timerIDs,"spinbat")
timer.Create("spinbat",1/30,4,function()
batent:SetPos(dispenser:GetPos()+Vector(x,y,54));
ba
Sorry for offtopic (I couldn't help with your question)
But did you code that sketch manually? Or some script spitted that? Looks too awesome!
Me and my notepad have been friends since Jedi Knight. ;)
Well, poking around a bit, turns out turning off the motion on Engi's 8th PhysicsObject (spine0) may have been the culprit. Re-enabling that, and setting its pos and angles constantly seems to get the head moving again.
Sorry, you need to Log In to post a reply to this thread.