Multiple Viewmodel Prediction Positions?

I have this weapon, the view model is never in the default position, even when you draw it it’s tilted to the side, ironsights. I want to interpolate from those settings to another set of settings. I’m a sadistic son of a… and I want to show the player turn the gun at their own face. Now, I can’t do this with VALVe’s models very well since they’re missing so many faces, so I positioned it just below the bottom of the screen.
So a short description:
You draw the weapon, holding it like a gangsta with well functioning ironsights
You want to kill yourself! You turn the gun so it faces your neck. This is the part I can’t figure out, how do I switch from one set of values to another.
I have tried dozens and dozens of ways, each one making sense… but no cigar!

A really easy way to help me, pretty simple actually, how does the engine position the viewmodel in the first place? If I knew how to do it myself from scratch I feel it would be much easier for me to move the gun around at any time!

Sounds like you are trying to do it on server, which is incorrect.

Are you able to show is your code so we can see why it the positions aren’t working properly? As for the suicide swep, I’ve seen it done before and have used it on a server as well so it is possible. There might be one publicly released that you could have a look into to see how they’ve done it.

Use GetViewModelPosition and Lerp.
When you return a different view position and angle the gun will change to fit that angle. This is usually how “iron sights” on guns work, as well as sprinting animations and the like. Lerp is what you want to gradtually move the weapon from the pointing animation to the other position, you can also use LerpVector and LerpAngle if you want.

I’ve tried so many sets of code!
No, I’m not trying to do it on SERVER, but I never did check for CLIENT…

[editline]1st February 2014[/editline]

Alright, thank you. I’ve gotten the model to stay idle at one unique position using GetViewModelPosition, this lerp thing may just finish the puzzle! Thank you!

[editline]1st February 2014[/editline]

So I guess making a variable for the time when the ironsights are asked to change, subtracting that from CurTime() to get how long we’ve wanted to change, and clamping the division, 0 to 1, that subtraction divided by the desired change time, then I’d use that as the lerp ratio, I prefer lerp angle and lerp vector, the first variables being the start and the second variables being the end sights, that should work right?

[editline]1st February 2014[/editline]

Oh yeah, and as for you thinking I’m doing it on server, I write everything I have in just one shared.lua file, doing if CLIENT and if SERVER checks.

[editline]1st February 2014[/editline]

But I looked at the code for the old CSS weapons that used to be in Garry’s Mod. Those weapons used a networked variable to control ironsights, can’t I just do it with a local variable within the file like SWEP.IronOn or something?

[editline]1st February 2014[/editline]


[ERROR] lua/weapons/con_sa_pistol/shared.lua:324: bad argument #2 to 'LerpAngle' (Angle expected, got userdata)
  1. LerpAngle - [C]:-1
   2. func - lua/weapons/con_sa_pistol/shared.lua:324
    3. unknown - gamemodes/base/gamemode/cl_init.lua:362

[lua]SWEP.Suicidal = false
– Suicide Iron Sights
SWEP.SIronP = Vector (5, -39, -10)
SWEP.SIronA = Vector (30, 125, 0)

– Active Iron Sights
SWEP.IronP = Vector (-5.96, -5, 2.777)
SWEP.IronA = Vector (1, -1, -44)

SWEP.LChange = CurTime()[/lua]

[lua]function SWEP:GetViewModelPosition( pos, ang )
local CTime = CurTime() - self.LChange
local LerpPerc = math.Clamp( CTime, 0, 1 )
if !self.Suicidal then LerpPerc = 0 end

local LerpVec = LerpVector( LerpPerc, self.IronP, self.SIronP )
local LerpAng = LerpAngle( LerpPerc, self.IronA, self.SIronA )

IPos = LerpVec
IAng = LerpAng

self.SwayScale 	= 1
self.BobScale 	= 2

ang = ang * 1
local Mul = 1
local Offset = IPos

ang:RotateAroundAxis( ang:Right(), 		IAng.x * Mul )
ang:RotateAroundAxis( ang:Up(), 		IAng.y * Mul )
ang:RotateAroundAxis( ang:Forward(), 	IAng.z * Mul )

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]

[editline]1st February 2014[/editline]

UserData is the error that has always haunted me!

You’re using Vector instead of Angle…
SWEP.SIronA = Angle (30, 125, 0)

Angles are not the same user data type as Vectors

Yeah, I fixed that, but when I designed the ironsights I used vector for the angle, if I use angle the ironsights get messed up! vector works, but I corrected that little error. Thank you!

So yes, you can actually use a Vector instead of an Angle here, but the values do not mean the exact same thing.
I’m still having so much trouble here, I’ve tried so many different methods to do this, but since none of them seemed to work I just scrapped the idea. I feel simply holstering the gun and playing a sound similar to that of pulling the hammer works well enough. By taking a viewpoint like that though, none of my weapons will have toggle-able ironsights. I don’t want that at all!

You don’t know, these weapons have a purpose, and while my last project is on hold for now, [sp]I received some interesting offers that I refuse to discuss[/sp], I have a new project, a simple one that only really needs existing VALVe content. I am currently using files from HL2 + EP1 & 2, CSS, and TF2, so the only drawback might be the requirement that you own those three franchises.

I refuse to discuss this new project in detail except with my trusted friends. You’ll get your information in due time. The only reason I share that is to let you know the help I’m asking for has a purpose. I will credit those who help me the most.

:quagmire:

It’s funny how you still don’t understand what your solution is even though you’ve had several people tell you the answer, and you’ve asked in multiple threads, which is unnecessary when you made your own thread already.

So how about you grow up and stop acting like the world revolves around you.

My rant against brandon completely put aside… all I want to say is I’m having trouble grasping the tips I’ve been given and putting them together, if anything all I need is more specific advice. Could someone please help me out here?


(User was banned for this post ("dumb 'get out' reply" - postal))