Implement rotation locking when standing, fix rotation unlock/lock for fly/swim mobs

This commit is contained in:
jordan4ibanez 2021-04-22 23:18:33 -04:00
parent fa059b5df2
commit aac1e19336
2 changed files with 29 additions and 0 deletions

View File

@ -102,6 +102,8 @@ local land_state_execution = function(self,dtime)
mobs.reverse_explosion_animation(self,dtime)
end
mobs.lock_yaw(self)
elseif self.state == "walk" then
self.walk_timer = self.walk_timer - dtime
@ -275,6 +277,8 @@ local swim_state_execution = function(self,dtime)
mobs.set_static_pitch(self)
end
mobs.lock_yaw(self)
elseif self.state == "swim" then
self.walk_timer = self.walk_timer - dtime
@ -307,6 +311,9 @@ local swim_state_execution = function(self,dtime)
if self.tilt_swim then
mobs.set_dynamic_pitch(self)
end
--enable rotation locking
mobs.movement_rotation_lock(self)
end
--flop around if not inside swim node
else
@ -415,6 +422,8 @@ local fly_state_execution = function(self,dtime)
mobs.set_static_pitch(self)
end
mobs.lock_yaw(self)
elseif self.state == "fly" then
self.walk_timer = self.walk_timer - dtime
@ -446,6 +455,10 @@ local fly_state_execution = function(self,dtime)
end
mobs.set_fly_velocity(self,self.walk_velocity)
--enable rotation locking
mobs.movement_rotation_lock(self)
elseif self.state == "attack" then
--execute mob attack type
@ -544,6 +557,8 @@ local jump_state_execution = function(self,dtime)
--set the velocity of the mob
mobs.set_velocity(self,0)
mobs.lock_yaw(self)
elseif self.state == "jump" then
self.walk_timer = self.walk_timer - dtime

View File

@ -136,6 +136,20 @@ mobs.set_yaw_while_attacking = function(self)
self.yaw = new_yaw
end
--this is used to unlock a mob's yaw after attacking
mobs.unlock_yaw = function(self)
if self.object:get_properties().automatic_face_movement_dir == false then
self.object:set_properties{automatic_face_movement_dir = self.rotate}
end
end
--this is used to lock a mob's yaw when they're standing
mobs.lock_yaw = function(self)
if self.object:get_properties().automatic_face_movement_dir then
self.object:set_properties{automatic_face_movement_dir = false}
end
end
local calculate_pitch = function(self)
local pos = self.object:get_pos()