]> git.lizzy.rs Git - Crafter.git/blob - mods/mob/api/animation.lua
7503fe71a89d4239223299d0338d48668d6d427e
[Crafter.git] / mods / mob / api / animation.lua
1 -- 
2 mobs.create_animation_functions = function(def,mob_register)
3     mob_register.set_animation = function(self)
4         if self.speed == 0 or vector.equals(self.direction,vector.new(0,0,0)) then
5             self.current_animation = 0
6             self.object:set_animation(def.standing_frame, 1, 0, true)
7         else
8             if self.current_animation ~= 1 then
9                 self.object:set_animation(def.moving_frame, 1, 0, true)
10                 self.current_animation = 1
11             end
12             
13             local speed = self.object:get_velocity()
14             speed.y = 0
15             self.object:set_animation_frame_speed(vector.distance(vector.new(0,0,0),speed)*def.animation_multiplier)
16         end
17     end
18
19     --this makes the mob rotate and then die
20     mob_register.manage_death_animation = function(self,dtime)
21         if self.death_animation_timer >= 0 and self.dead == true then
22             self.death_animation_timer = self.death_animation_timer - dtime
23             
24             local self_rotation = self.object:get_rotation()
25             
26             if self.death_rotation == "x" then
27                 if self_rotation.x < math.pi/2 then
28                     self_rotation.x = self_rotation.x + (dtime*2)
29                     self.object:set_rotation(self_rotation)
30                 end
31             elseif self.death_rotation == "z" then
32                 if self_rotation.z < math.pi/2 then
33                     self_rotation.z = self_rotation.z + (dtime*2)
34                     self.object:set_rotation(self_rotation)
35                 end
36             end
37             
38             --print(self.death_animation_timer)
39             local currentvel = self.object:getvelocity()
40             local goal = vector.new(0,0,0)
41             local acceleration = vector.new(goal.x-currentvel.x,0,goal.z-currentvel.z)
42             acceleration = vector.multiply(acceleration, 0.05)
43             self.object:add_velocity(acceleration)
44             self.object:set_animation({x=0,y=0}, 15, 0, true)
45         end
46     end
47     return(mob_register)
48 end