Hiya everyone, i've been working on some melee weapons for one of my servers. My initial reaction to fixing them was to remove that gawd-awful crowbar animation, and replace it with an intricate lua-animation system.
My issue here is that the viewmodel returns to null vector and angle after every angle/vector change (Returns to 0,0,0 for both) before moving on to the next angle/position. How can i change my script to keep the last angles and vector before moving on to the next one, so it doesnt go back to zero before each change?
[lua]
function SWEP:GetViewModelPosition(pos, ang)
if self:IsSwinging() then
local rot = self.SwingRotation or Angle(0,0,0) -- Changes based on shared timer
local offset = self.SwingOffset or Vector(0,0,0) --same as above
--print(rot)
--print(offset)
ang = Angle(ang.pitch, ang.yaw, ang.roll) -- Copy
local swingend = self:GetSwingEnd()
local phaseend = self:GetNextPhase()
local delta = self.SwingTime - math.max(0, phaseend - CurTime()) -- calculates a smooth transition
local power = CosineInterpolation(0, 1, delta / self.PhaseTime) -- same here, thanks for this tad jetboom!
if power >= 0.9 then --math bits
power = (1 - power) ^ 0.4 * 2
end
pos = pos + offset.x * power * ang:Right() + offset.y * power * ang:Forward() + offset.z * power * ang:Up()
ang:RotateAroundAxis(ang:Right(), rot.pitch * power)
ang:RotateAroundAxis(ang:Up(), rot.yaw * power)
ang:RotateAroundAxis(ang:Forward(), rot.roll * power)
if pos == offset and ang == rot then
pos = offset
ang = rot
end
end
return pos, ang
end
[/lua]
Here's a video of what it does, don't mind the weird angles i put in, it's just for testing.
[vid]http://puu.sh/3DEPF.webm[/vid]
Any help would be appreciated, this one is a bit of a mind bender.
If you need any more code to help you figure out what's up with this, please tell me.
Thanks in advance!
[editline]15th July 2013[/editline]
i've found the issue, i just don't know how to implement a fix.
With the start of each new phase, it's starting back at the beginning with power, which at first, equals zero.
So, Each time, it goes from Vector 0,0,0 to the end vector of that phase, causing it to do this.
The thing i need to do is cause that math to start at the point in time where the last vector was, if that makes any sense.
I think i may need to throw out the cosine interpolation and use LerpAngle.
Another update, Cosine Interp doesn't need to be removed. I've gotten a step closer, but not close enough.
[editline]15th July 2013[/editline]
Alright, Got most of it, i think it's just a matter of getting the angle to lerp correctly.
[editline]15th July 2013[/editline]
Okay, this should be at least a bit better to understand
[lua]
local lastangle = Angle(0,0,0)
local lastoffset = Vector(0,0,0)
local lastphase = 1
function SWEP:GetViewModelPosition(pos, ang)
if self:IsSwinging() then
--print(lastangle)
--print(lastoffset)
local rot = self.SwingRotation
local offset = self.SwingOffset
--print(rot)
--print(offset)
ang = Angle(ang.pitch, ang.yaw, ang.roll) -- Copy
local swingend = self:GetSwingEnd()
local phaseend = self:GetNextPhase()
if lastphase < self:GetCurrentPhase() then
-- print(self:GetCurrentPhase())
if self.SwingRotOffTBL[self:GetCurrentPhase() - 1] then
--print("OHSHITE")
lastangle = self.SwingRotOffTBL[self:GetCurrentPhase() -1 ].rot
lastoffset = self.SwingRotOffTBL[self:GetCurrentPhase() - 1].off
-- print(lastangle)
--print(lastoffset)
else
lastangle = Angle(0,0,0)
lastoffset = Vector(0,0,0)
end
end
local delta = self.SwingTime - math.max(0, phaseend - CurTime())
local power = CosineInterpolation(1, 0, delta / self.PhaseTime)
-- print(power)
/*if power >= 0.9 then
power = (1 - power) ^ 0.4 * 2
-- print("p"..power)
end*/
local interp = (phaseend - CurTime()) * self.PhaseTime
local interp2 = math.Approach(0,self.PhaseTime, 0.1) / self.PhaseTime
pos = pos + offset.x /** power*/ * ang:Right() + offset.y /** power*/ * ang:Forward() + offset.z /** power*/ * ang:Up()
print(LerpAngle(power, lastangle,rot))
ang:RotateAroundAxis(ang:Right(), LerpAngle(power, lastangle,rot).pitch)
ang:RotateAroundAxis(ang:Up(), LerpAngle(power, lastangle,rot).yaw)
ang:RotateAroundAxis(ang:Forward(), LerpAngle(power, lastangle,rot).roll)
if pos == offset and ang == rot then
lastoffset = offset
lastangle = rot
end
else
lastangle = Angle(0,0,0)
lastoffset = Vector(0,0,0)
end
return pos, ang
end
[/lua]
I've got the numbers down, the "power" function goes from 0 to 1 over the course of time of PhaseTime, but for some reason the LerpAngle keeps on returning the default value of "rot"
Whats up with that?
Also, using normal Lerp with specific values of the angle also does the same thing.
Sorry, you need to Log In to post a reply to this thread.