• KeyDown is giving me trouble with IN_LEFT, IN_RIGHT.
    0 replies, posted
  • Avatar of flyguy88
  • I got KeyDown to work fine to IN_FORWARD and IN_BACKWARD but doesn't seem to work for IN_LEFT or IN_RIGHT. Sorry if this has been addressed before, search not working. Init.lua(serverside) [code] function GM:Move(pl, move) --[[if pl.jetpack == true then if pl:KeyDown(IN_FORWARD) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * 1.2 ) elseif pl:KeyDown(IN_LEFT) then print("hng") move:SetVelocity(move:GetVelocity() + pl:GetRight() * -2) elseif pl:KeyDown(IN_RIGHT) then move:SetVelocity(move:GetVelocity() + pl:GetRight() * 2) elseif pl:KeyDown(IN_BACK) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * -1.2) end end]]-- local deltatime = 0 if (CurTime() >= deltatime) then if pl.jetpack == true then deltatime = CurTime() + 0.1 local boostmagnitude = 6 -- default50 local effectback = -15 --local sound_delay = 0 if (pl.boost > 0) then local cmd = pl:GetCurrentCommand() if (cmd:KeyDown(IN_FORWARD)) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * 2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) elseif (cmd:KeyDown(IN_BACK)) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * -2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) elseif (cmd:KeyDown(IN_LEFT)) then move:SetVelocity(move:GetVelocity() + pl:GetRight() * -2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) else move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude) end pl.boost = math.Clamp(pl.boost - global_boostreductionrate, 0, 100) local bone = pl:LookupBone("ValveBiped.Bip01_Spine2") local bpos = pl:GetBonePosition(bone) local finalpos = bpos + pl:GetForward() * effectback if CurTime() > sounddelay then pl:EmitSound(jetpacksound) sounddelay = CurTime() + rsounddelay end --if CurTime() > sound_delay then --pl:EmitSound(jetpacksound) --sound_delay = CurTime() + 0.5 --end --ParticleEffect("jetpack", pl:GetPos(), Angle(0,0,0), nil) --ParticleEffectAttach("jetpack",PATTACH_ABSORIGIN_FOLLOW,self,0) end end end end [/code] [code] local cmd = pl:GetCurrentCommand() if (cmd:KeyDown(IN_FORWARD)) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * 2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) elseif (cmd:KeyDown(IN_BACK)) then move:SetVelocity(move:GetVelocity() + pl:GetForward() * -2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) elseif (cmd:KeyDown(IN_LEFT)) then move:SetVelocity(move:GetVelocity() + pl:GetRight() * -2 ) move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude/3) else move:SetVelocity(move:GetVelocity() + pl:GetUp() * boostmagnitude) end [/code] I've tried it with simply pl:KeyDown() but that doesn't work either. [editline]8th June 2012[/editline] solved, I was suppose to use IN_MOVELEFT and IN_MOVERIGHT.