I feel very stupid having to make a thread for this, but I've tried so many different things and none of them have worked.
So, this amazing guy (grobov13) gave me this fantastic effect code that could be used to animate an entity's physbones:
[CODE]
-- This is a slightly modified version of grobov13's code - he's a legend
function EFFECT:Init( data )
self.ent = data:GetEntity()
if !IsValid( self.ent ) then return end
self:SetModel( self.ent:GetModel() )
self:SetAngles( self.ent:GetAngles() )
self:SetSequence( math.Round( data:GetMagnitude() or 1 ) )
self:SetPlaybackRate( 1 )
self.DieTime = ( self:SequenceDuration() * 0.95 ) + CurTime()
self.LastRender = 0
end
function EFFECT:Think()
if IsValid( self.ent ) then
for i = 0, self.ent:GetPhysicsObjectCount() - 1 do
local translate = self:TranslatePhysBoneToBone( i )
if translate and 0 < translate then
local pos, ang = self:GetBonePosition( translate )
if ( pos and ang ) then
local phys = self.ent:GetPhysicsObjectNum( i )
if IsValid( phys ) then
phys:Wake()
phys:ComputeShadowControl({
secondstoarrive = 0.10,
pos = pos,
angle = ang,
maxangular = 2000,
maxangulardamp = 10000,
maxspeed = 5000,
maxspeeddamp = 1000,
dampfactor = 0.8,
teleportdistance = 100,
deltatime = RealFrameTime()
})
end
end
end
end
self:NextThink( CurTime() )
end
return self.DieTime and ( self.DieTime > CurTime() )
end
function EFFECT:Render()
self:FrameAdvance( ( RealTime() - ( self.LastRender or 0 ) ) * 1 )
self.LastRender = RealTime()
end
[/CODE]
That code works great if you want to animate an entity to perform a short sequence, but anything longer than that seems to break. Let me show you:
[CODE]
hook.Add( 'DoPlayerDeath', 'DeathTest', function( victim, attacker, dmginfo )
local rag = victim:GetRagdollEntity()
if !IsValid( rag ) then victim:CreateRagdoll() end -- We need a ragdoll for this
local id, duration = victim:LookupSequence( 'taunt_robot' ) -- taunt_robot is a long sequence that bugs out
local effect = EffectData()
effect:SetEntity( victim:GetRagdollEntity() )
effect:SetOrigin( victim:GetPos() )
effect:SetMagnitude( id )
util.Effect( "animator", effect, true, true ) -- This is the effect from before
end )
[/CODE]
If you copy that effect code from before into lua/effects/animator.lua and then you run the thing above serverside, then you should be able to see that when you die your ragdoll performs taunt_robot.
However, if you leave it running for a little bit longer, you should see it stop moving, and if you open and close the console, then (for me at least) the ragdoll completely spazzes out and goes to Vector(0,0,0).
I have absolutely no clue as to what is causing this problem, but I've tried a lot of stuff and nothing works, so hopefully someone here who knows more about effects could attempt to figure it out.
Bump.
Bump. I'm now 99% sure the reason the effect stops moving is because of the ComputeShadowControl part, but I don't know why it goes up in the air
Actually, I think I'll open a more specific thread, this is too confusing for anyone wanting to solve it
Sorry, you need to Log In to post a reply to this thread.