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