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