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