Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Handles the movement animations
- --]]
- local fade=.2
- --communicate with roblox animation script
- local angletodir={'f','lf','l','lb','b','rb','r','rf','f',}
- local speeds={
- f=.075,
- lf=.075,
- rf=.075,
- l=.075,
- r=.075,
- lb=.075,
- rb=.075,
- b=.075,
- }
- local walk={
- f=16,
- lf=16,
- rf=16,
- l=16,
- r=16,
- lb=16,
- rb=16,
- b=16,
- }
- local md={
- dir=nil,
- changed=_G.signal(),
- wsmult=1,--walk speed multiplier
- _changed=_G.signal(),--internally called by CharacterScripts.Animate
- }
- local maid=_G.maid()
- _G.bindspawned(function(char)
- _G.died(char):bind(function()
- maid()
- if md.dir then
- md.dir=nil
- md.changed(nil)
- end
- end)
- local hum=_G.hum
- local hrp=_G.hrp
- local anims={}
- for _,v in next,script:GetChildren()do
- anims[v.Name]=hum:LoadAnimation(v)
- anims[v.Name].Priority=Enum.AnimationPriority.Core
- end
- local track
- local function getdir()
- local dir=(((hrp.CFrame-hrp.Position):inverse()*hrp.Velocity)*Vector3.new(1,0,1)).Unit
- local x,z=dir.X,dir.Z
- local a=math.atan2(-x,-z)%(math.pi*2)
- for i=1,#angletodir do
- if a<=math.rad(22.5)then
- return angletodir[i]
- end
- a=a-math.rad(22.5)*2
- end
- end
- local function getanim()
- local dir=getdir()
- if md.dir~=dir then
- md.dir=dir
- md.changed(dir)
- end
- hum.WalkSpeed=walk[dir]*md.wsmult
- return anims[dir],speeds[dir]*(hrp.Velocity*Vector3.new(1,0,1)).magnitude/md.heightscale()
- end
- maid(_G.beat:Connect(function(dt)
- if not md.dir then return end
- local new,speed=getanim()
- if new==track then
- track:AdjustSpeed(speed)
- else
- local pos=track.TimePosition
- track:Stop(fade/2)
- track=new
- track:Play(fade,1,speed)
- track.TimePosition=pos
- end
- end))
- maid(md._changed:bind(function(status)--the CharacterScripts.Animate calls this to tell whether or not character is moving
- if status==(md.dir~=nil)then return end
- if status then
- local speed
- track,speed=getanim()
- track:Play(fade,1,speed)
- else
- md.dir=nil
- md.changed(nil)
- track:Stop(fade*2)
- track=nil
- end
- end))
- end)
- return md
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement