Added flying function for mobs (thanks D00Med)

This commit is contained in:
TenPlus1 2017-02-21 15:01:36 +00:00
parent 8201282022
commit 3d1f62b196
3 changed files with 76 additions and 1 deletions

15
api.txt
View File

@ -1,5 +1,5 @@
MOB API (31st January 2017)
MOB API (21st February 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -298,6 +298,19 @@ This function allows an attached player to move the mob around and animate it at
'dtime' tick time used inside drive function
mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
This function allows an attached player to fly the mob around using directional controls.
'self' mob information
'dtime' tick time used inside fly function
'speed' speed of flight
'can_shoot' true if mob can fire arrow (sneak and left mouse button fires)
'arrow_entity' name of arrow entity used for firing
'move_animation' string containing movement animation e.g. "walk"
'stand_animation' string containing movement animation e.g. "stand"
Certain variables need to be set before using the above functions:
'self.v2' toggle switch

View File

@ -370,3 +370,64 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
entity.v2 = v
end
-- directional flying routine by D00Med (edited by TenPlus1)
function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity()
local dir = entity.driver:get_look_dir()
local yaw = entity.driver:get_look_yaw()
local rot_steer, rot_view = math.pi / 2, 0
if entity.player_rotation.y == 90 then
rot_steer, rot_view = 0, math.pi / 2
end
if ctrl.up then
entity.object:setvelocity({
x = dir.x * speed,
y = dir.y * speed + 2,
z = dir.z * speed
})
elseif ctrl.down then
entity.object:setvelocity({
x = -dir.x * speed,
y = dir.y * speed + 2,
z = -dir.z * speed
})
elseif not ctrl.down or ctrl.up or ctrl.jump then
entity.object:setvelocity({x = 0, y = -2, z = 0})
end
entity.object:setyaw(yaw + math.pi + math.pi / 2 - entity.rotate)
-- firing arrows
if ctrl.LMB and ctrl.sneak and shoots then
local pos = entity.object:getpos()
local obj = minetest.add_entity({
x = pos.x + 0 + dir.x * 2.5,
y = pos.y + 1.5 + dir.y,
z = pos.z + 0 + dir.z * 2.5}, arrow)
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
local yaw = entity.driver:get_look_yaw()
obj:setyaw(yaw + math.pi / 2)
obj:setvelocity(vec)
end
-- change animation if stopped
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
set_animation(entity, stand_anim)
else
-- moving animation
set_animation(entity, moving_anim)
end
end

View File

@ -23,6 +23,7 @@ Lucky Blocks: 9
Changelog:
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112
- 1.32- Added new spawn check to count specific mobs AND new minetest.conf setting to chance spawn chance and numbers, added ability to protect tamed mobs
- 1.31- Added 'attack_animals' and 'specific_attack' flags for custom monster attacks, also 'mob_difficulty' .conf setting to make mobs harder.