So i am currently using a slightly modified version of a headbob i found on garrysmod.org but the circle motion is making people nautious. So i was wondering how i could make it more 'random' and more in a motion of this
'semi-motion' i'm looking for (Also there's a lot of headbobbing going on so it should be only slight movement)
[IMG]http://upload.wikimedia.org/wikipedia/en/thumb/0/01/ABCTV1975.svg/401px-ABCTV1975.svg.png[/IMG]
Code i'm using
[LUA]
--[[
Name: HeadBob.
-
Author: ProSoft.
-
Edited: Classified
-
Description: "Gives your screen a headbob effect."
-
--]]
// Head Bob
local HeadBobVar = CreateConVar( "cl_headbob", "1", { FCVAR_REPLICATED, FCVAR_ARCHIVE } )
if ( SERVER ) then
AddCSLuaFile("sh_headbob.lua")
end
-- The angles
HeadBobAng = 0;
-- X
HeadBobX = 0;
-- y
HeadBobY = 0;
if ( CLIENT or SERVER ) then
function HeadBob( ply, origin, angles, fov )
if( IsValid( LocalPlayer() ) ) then
if( HeadBobAng > 360 ) then HeadBobAng = 0; end
if( HeadBobVar:GetBool() ) then
local view = { }
view.origin = origin;
view.angles = angles;
-- Idle Bob
if (ply:GetVelocity():Length() == 0) then
HeadBobAng = HeadBobAng + 2 * FrameTime();
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * .2;
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .1;
end
--Jump Bob
if( !ply:IsOnGround() and ply:WaterLevel() <= 0.5) then
HeadBobAng = HeadBobAng + 6 * FrameTime();
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * 7;
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .6;
end
if( ( ply:KeyDown( IN_FORWARD ) or
ply:KeyDown( IN_BACK ) or
ply:KeyDown( IN_MOVERIGHT ) or
ply:KeyDown( IN_MOVELEFT ) ) and ply:IsOnGround()) then
--Run Bob
if( ply:GetVelocity():Length() > 150 ) then
HeadBobAng = HeadBobAng + 10 * FrameTime();
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * 2.5;
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .6;
else --Walk Bob
HeadBobAng = HeadBobAng + 3 * FrameTime();
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * 1.3;
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .9;
end
return view;
end
local view = { }
view.origin = origin;
view.angles = angles;
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng );
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng );
return view;
end
end
end
end
hook.Add( "CalcView", "HeadBob", HeadBob );
[/LUA]
Also is there a way to only calc view on localplayers footstep?
Sorry, you need to Log In to post a reply to this thread.