• Changing the Way a Model is Viewed
    21 replies, posted
Is there a code snippet that allows me to change how the v_model is displayed? I want, specifically, to make the ironsight coordinates the way the SWEP is viewed when drawn. Thanks for your time, and I'll be happy to answer any more questions if the above request isn't very clear.
This might help: [url]http://www.garrysmod.org/downloads/?a=view&id=29787[/url]
No, what I want to do is make the ironsights what the player looks at when they draw the weapon. Specifically, I want to make an FN-SCAR that's closer to the player like it is in L4D2.
[lua]function SWEP:GetViewModelPosition(pos, ang) pos = pos + ang:Forward()*-64 return pos, ang end[/lua] This will move the view model 64 units back.
Thanks. I'll give this a try.
[QUOTE=Marlwolf78;19828682]No, what I want to do is make the ironsights what the player looks at when they draw the weapon. Specifically, I want to make an FN-SCAR that's closer to the player like it is in L4D2.[/QUOTE] OH! Well you could create a function that brings the ironsights in and do [lua] function SWEP:Deploy() //you should know this shtuff end end [/lua] Or something.
So you just want to shift the viewmodel position a bit on a SWEP?
Basically. I'm going to try out the code Null gave me, and see if the results are satisfactory.
You might be looking for [url=http://wiki.garrysmod.com/?title=SWEP.GetViewModelPosition]SWEP.GetViewModelPosition[/url]. Lets you alter the angle and position of the view model. [editline]10:03PM[/editline] You might be looking for [url=http://wiki.garrysmod.com/?title=SWEP.GetViewModelPosition]SWEP.GetViewModelPosition[/url]. Lets you alter the angle and position of the view model.
[QUOTE=NullPoint;19828770][lua]function SWEP:GetViewModelPosition(pos, ang) pos = pos + ang:Forward()*-64 return pos, ang end[/lua] This will move the view model 64 units back.[/QUOTE] [QUOTE=MegaJohnny;19828945]You might be looking for [url=http://wiki.garrysmod.com/?title=SWEP.GetViewModelPosition]SWEP.GetViewModelPosition[/url]. Lets you alter the angle and position of the view model.[/QUOTE] Rated late.
Ok, the code you gave me doesn't seem to do anything to the model. Are you sure it's correct?
I'm not sure, try this instead: [lua]function SWEP:GetViewModelPosition(pos, ang) local pos = pos + ang:Forward()*-64 return pos, ang end[/lua] [editline]10:37PM[/editline] If that doesn't work, you may have overridden CalcView.
OK, whatever CalcView is, it must be overridden. How do I enable it?
That might not be it, though, can't help to add some nice debug lines. Try something like this, hold down space and see what happens: [lua] function SWEP:GetViewModelPosition(pos, ang) if LocalPlayer():KeyDown(IN_JUMP) then pos = pos + ang:Forward()*-64 Msg("HELLO") end return pos, ang end [/lua]
I'll give it a try. Thank you.
I've tried that... the model goes away, I can't see it anymore when I press the jump button. In less words: It works.
[QUOTE=lonewolf2;19859685]I've tried that... the model goes away, I can't see it anymore when I press the jump button.[/QUOTE] If the units of the view model are the same as the world units I'm not surprised - you're essentially moving it 64 units behind where it normally is.
Just edit the FOV in the sharedl.lua
That doesn't work. I've tried different values, and it doesn't seem to do anything.
Why not using / reading a SWEP base that currently has iron sights (madcows or realistic cs, not sure) and extracting the code out of it? [editline]07:49AM[/editline] To spare you some work, here is the exact code used for iron sights in realistic swep base( [url]http://www.facepunch.com/showthread.php?p=7711423[/url] ). [LUA] local IRONSIGHT_TIME = 0.35 function SWEP:GetViewModelPosition(pos, ang) if not self.IronSightsPos then return pos, ang end local bIron = self.Weapon:GetNetworkedBool("Ironsights") if bIron ~= self.bLastIron then -- Are we toggling ironsights? self.bLastIron = bIron self.fIronTime = CurTime() if bIron then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if not bIron and (fIronTime < CurTime() - IRONSIGHT_TIME) then return pos, ang end local Mul = 1.0 -- we scale the model pos by this value so we can interpolate between ironsight/normal view if fIronTime > CurTime() - IRONSIGHT_TIME then Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1) if not bIron then Mul = 1 - Mul end end local Offset = self.IronSightsPos if self.IronSightsAng then ang = ang*1 ang:RotateAroundAxis(ang:Right(), self.IronSightsAng.x * Mul) ang:RotateAroundAxis(ang:Up(), self.IronSightsAng.y * Mul) ang:RotateAroundAxis(ang:Forward(), self.IronSightsAng.z * Mul) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end [/LUA] Hope you can get something out of it =)
How to make it moves left or right? [QUOTE=Marlwolf78;19872838]That doesn't work. I've tried different values, and it doesn't seem to do anything.[/QUOTE] It works perfectly to me.
[QUOTE=lonewolf2;19896949]How to make it moves left or right? It works perfectly to me.[/QUOTE] If you mean in NullPoint's code, change the ang:Forward() to ang:Right() Positive values in the multiplication move it to the right, negative moves it to the left.
Sorry, you need to Log In to post a reply to this thread.