I’m making a jetpack, which sets the player’s velocity when holding WASD and spacebar.
It works fine on servers with 66 tickrate. When I tried it on 20 tickrate, it became extremely weak and could barely lift the player. And in single player, it became extremely overpowered.
I figured it’s because Think() executes once every tick serverside, so I tried making a tick multiplier variable. so for example, on 33 tickrate, the multiplier would be 2 since Think() is only called 33 times per second instead of 66.
It works well to scale the fuel consumption and recharge rate, but completely f*cks up velocity calculations and overpowers them.
(to undo the TickMultiplier calculation, it’s possible to just set the tm variable to 1)
function ITEM:Think(ply, modifications) if (SERVER) then local tm = 66.6 / engine.TickInterval() --gets (T)ick (M)ultiplier to adjust velocity calculations and fuel consumption. if ply:KeyDown(IN_JUMP) then ply.Jetpackfuel = math.max(0, ply.Jetpackfuel - 1*tm) local i = math.floor( math.min(10,-0.1+ply.Jetpackfuel) / 10 ) -- returns -1 at 0 fuel, 0 below 10 fuel, and 1 above 10 fuel. if i ~= -1 then ply:SetVelocity( ply:GetUp() * tm * ( 17 + i*10 ) + ply:GetForward()*tm*(10 + i*7)*( (ply:KeyDown(IN_FORWARD) and 1 or 0)-(ply:KeyDown(IN_BACK) and 1 or 0) ) + ply:GetRight()*tm*(10 + i*7)*( (ply:KeyDown(IN_MOVERIGHT) and 1 or 0)-(ply:KeyDown(IN_MOVELEFT) and 1 or 0) ) -ply:GetVelocity()*Vector(3,3,2+i)*0.01*tm ) end else ply:SetVelocity( -ply:GetVelocity()*Vector(0,0,1)*0.01*tm ) end if(ply.Jetpackfuel < 100) then ply.Jetpackfuel = ply.Jetpackfuel + 0.25*tm end end end
So how do I solve setting velocity of items on different tickrates?