Leaning?

Is it possible to make it so that players can lean, for instance like Call of Duty 4? I doubt its possibility but I am hoping I can get some code written up that allows people you lean using Q & E, it is for my TTT server.
My main concern is that people will not be able to see a leaning player lean.

Thanks.

hmm the world view is a concern but it is possible by hooking it into CalcView

something like:
[lua]
hook.Add(“PlayerBindPressed”, function(b)
// hook it so we dont override!
if (b == “+leanleft”) then
LocalPlayer().Leaning = 1;
elseif (b == “+leanright”) then
LocalPlayer().Leaning = 0;
end
end)

function GM:CalcView(ply, origin, angles, fov)
// !ply.Leaning will return true if its 0 so check for nil!
if (ply.Leaning == nil) then return; end

local view = {};

if (ply.Leaning)
	view.origin = ply:GetPos() + ply:GetLeft() * 2;
	view.angles = angles + Angle(35, 0, 0);
else
	view.origin = ply:GetPos() + ply:GetLeft() * 0.5;
	view.angles = angles - Angle(35, 0, 0);
end

return view;

end
[/lua]

i just made the vector and angle offsets up but something similar to that should work :slight_smile:

In Lua, everything that isnt nil or false is true so doing !LocalPlayer().Leaning when it is zero would return false. But your method would work as far as the leaning

sorry ye thats my mistake XD so used to C++, java and php where everything is false is its 0.

anyways doesnt really matter the code should still work as planned.

You’re right. They won’t be seen unless you use a model with a leaning animation. Most likely bullets will also still originate from the original position instead of the leaning position as well, but I can’t really remember the issue with that.

yep what -TB- said is correct.

people wont be able to see the lean (only the player who is leaning) and shooting will shoot from the normal position

I thought that would be the case.

Doesn’t it also break weapon positions? Like if you want to setup ironsights(GetViewModelPosition()) the gun won’t actually move.

viewmodels are clientside

so when the camera moves, the weapon moves, unless itw scripted no to do so

If leaning is in anyway do able I will be forever in FacePunchs debt.

i believe i sent you the code before…

Could you tell me what I do with it exactly? And what about the fact that it doesn’t change the world model and all those other errors that were brought up?

they arent technically errors and unless you get someone to add in leaning animations to the player models or do it your self (which would require all player models to be decompiled, have the animations added then recompiled and everyone would have to redownload them) you will have to make do with it being client side only.

my advice is to just make it a feature, dont worry about adjusting the shooting position.

the code needs to go in any client file. if you use it inside of the gamemode it should be fine, but if you use it outside of the gamemode or there is already an overridden CalcView just hook it in with hook.Add.

or make a player model with a leaning animation and bonemerged it to the current player model.

and the shooting position would be pretty easy to to change in SWEPs

as for cleintside only, peeking around corners might be the best solution.

didnt i just say that?

I’m not sure if they’d work in Garry’s Mod, but I think Insurgency player models have a leaning animation.

if you post in here:
http://facepunch.com/forumdisplay.php?f=40
make a new thread for an animation request someone might make them for you.

maybe even maxofs2d will do them and break the arms, who knows.

Theoretically, you could make the upper body bend over if you know how to code it via twisting the right bone a little, but it’d look awkward and probably not work too well - or be a bit crappy for the end result.

Perhaps the best that can be done it to make it so that when you lean it puts away your weapon, and you can just look. People won’t be able to see you lean but it could be handy for people to just quickly check around corners.

that works well, but hitbox won’t move togheter. and only way to include leaning position with proper hitbox problem is compiling new invisible playermodel.