Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- handles Animating OTHER rigs, other than our local Luanoid.
- local References = require(game:GetService("ReplicatedStorage").Utilities.Services.References)
- local Utilities = References.Utilities
- local Services = Utilities.Services
- local Api = require(References.PlayerScripts.Main:WaitForChild("Character"):WaitForChild("Controller"):WaitForChild("Api"))
- local Other = {}
- -- list of rigs with stored animation tracks.
- Other.Rigs = {}
- function Other:SetupRig(rig)
- if not self.Rigs[rig] then -- anti-leak
- self.Rigs[rig] = {}
- self.Rigs[rig].Connection = rig.AncestryChanged:Connect(function()
- if not rig.Parent then
- self.Rigs[rig].Connection:Destroy()
- self.Rigs[rig] = nil
- end
- end)
- end
- self.Rigs[rig].Animations = self.Rigs[rig].Animations or {}
- end
- function Other:MakeTrack(controller, id)
- if controller and id then
- local animation = Instance.new("Animation")
- animation.AnimationId = id
- return controller:LoadAnimation(animation)
- end
- end
- function Other:Animate(rig, name, id, play_stop)
- local controller = rig and rig:FindFirstChild("AnimationController") or Instance.new("AnimationController")
- controller.Parent = rig
- if controller then
- self:SetupRig(rig)
- local track = self.Rigs[rig].Animations[name]
- if track then
- local track_id = track.Animation.AnimationId
- if track_id ~= id then
- -- make new track. A different anim id for the given name is being play (alt/weighted anim handling)
- track = self:MakeTrack(controller, id)
- self.Rigs[rig].Animations[name] = track
- end
- if play_stop then
- track:Play()
- else
- track:Stop()
- end
- else
- if play_stop then
- track = self:MakeTrack(controller, id)
- self.Rigs[rig].Animations[name] = track
- track:Play()
- --else
- -- -- being told to stop an animation we don't have a track for, who cares.
- end
- end
- end
- end
- function Other:AdjustSpeed(rig, name, id, speed)
- -- get or make track
- -- track:AdjustSpeed(speed)
- local controller = rig and rig:FindFirstChild("AnimationController") or Instance.new("AnimationController")
- controller.Parent = rig
- self:SetupRig(rig)
- local track = self.Rigs[rig].Animations[name] or self:MakeTrack(controller, id)
- self.Rigs[rig].Animations[name] = track
- track:AdjustSpeed(speed)
- end
- Api.Bindables.ReplicateAnimation.Event:Connect(function(rig, name, id, play_stop)
- -- get or load the track into rig.AnimationController
- Other:Animate(rig, name, id, play_stop)
- end)
- return Other
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement