Major improvements for flying entities

Previously, if the entity had the `can_fly` option enabled, when
going upwards or downwards, it went too fast, extremely fast, and its speed increases over time.

With this update, this no longer happens: you can customize your
own upwards and downwards maximum speed for any entity you want.
This commit is contained in:
David Leal 2021-03-24 12:32:23 -06:00
parent 00ff618640
commit 274a729ef5
No known key found for this signature in database
GPG Key ID: 3C482B03FD220E68
2 changed files with 45 additions and 7 deletions

View File

@ -1,9 +1,9 @@
# Library Mount [![Build status](https://github.com/Panquesito7/lib_mount/workflows/build/badge.svg)](https://github.com/Panquesito7/lib_mount/actions) [![License](https://img.shields.io/badge/license-LGPLv2.1%2B-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) [![ContentDB](https://content.minetest.net/packages/Panquesito7/lib_mount/shields/downloads/)](https://content.minetest.net/packages/Panquesito7/lib_mount/)
# Library Mount [![Build status](https://github.com/minetest-mods/lib_mount/workflows/build/badge.svg)](https://github.com/minetest-mods/lib_mount/actions) [![License](https://img.shields.io/badge/license-LGPLv2.1%2B-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) [![ContentDB](https://content.minetest.net/packages/Panquesito7/lib_mount/shields/downloads/)](https://content.minetest.net/packages/Panquesito7/lib_mount/)
Made by [blert2112](https://github.com/blert2112).\
Handed over to [Panquesito7](https://github.com/Panquesito7).
Current version: 1.2
Current version: 1.3
## Dependencies
@ -29,11 +29,11 @@ See [`LICENSE.md`](LICENSE.md) for information.
## Installation
- Unzip the archive, rename the folder to `lib_mount` and place it in ../minetest/mods/
- Unzip the archive, rename the folder to `lib_mount` and place it in `../minetest/mods/`.
- GNU/Linux: If you use a system-wide installation place it in ~/.minetest/mods/.
- GNU/Linux: If you use a system-wide installation, place it in `~/.minetest/mods/`.
- If you only want this to be used in a single world, place the folder in worldmods/ in your world directory.
- If you only want this to be used in a single world, place the folder in `worldmods/` in your world directory.
For further information or help, see:\
<http://wiki.minetest.net/Installing_Mods>.

View File

@ -278,13 +278,13 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
velo.y = velo.y + (jump_height * 3) + 1
acce_y = acce_y + (acce_y * 3) + 1
end
if can_go_down and can_go_up and can_fly and can_fly == true then
if can_go_up and can_fly and can_fly == true then
velo.y = velo.y + 1
acce_y = acce_y + 1
end
end
if ctrl.sneak then
if can_go_down and can_go_up and can_fly and can_fly == true then
if can_go_down and can_fly and can_fly == true then
velo.y = velo.y - 1
acce_y = acce_y - 1
end
@ -317,6 +317,24 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
return
end
-- Stop! (upwards and downwards; applies only if `can_fly` is enabled)
if can_fly == true then
local s2 = get_sign(velo.y)
local s3 = get_sign(acce_y)
velo.y = velo.y - 0.02 * s2
acce_y = acce_y - 0.02 * s3
if s2 ~= get_sign(velo.y) then
entity.object:set_velocity({x=0, y=0, z=0})
velo.y = 0
return
end
if s3 ~= get_sign(acce_y) then
entity.object:set_velocity({x=0, y=0, z=0})
acce_y = 0 -- luacheck: ignore
return
end
end
-- enforce speed limit forward and reverse
local max_spd = entity.max_speed_reverse
if get_sign(entity.v) >= 0 then
@ -326,6 +344,25 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
entity.v = entity.v - get_sign(entity.v)
end
-- Enforce speed limit when going upwards or downwards (applies only if `can_fly` is enabled)
if can_fly == true then
local max_spd_flying = entity.max_speed_downwards
if get_sign(velo.y) >= 0 or get_sign(acce_y) >= 0 then
max_spd_flying = entity.max_speed_upwards
end
if math.abs(velo.y) > max_spd_flying then
velo.y = velo.y - get_sign(velo.y)
end
if velo.y > max_spd_flying then -- This check is to prevent exceeding the maximum speed; but the above check also prevents that.
velo.y = velo.y - get_sign(velo.y)
end
if math.abs(acce_y) > max_spd_flying then
acce_y = acce_y - get_sign(acce_y)
end
end
-- Set position, velocity and acceleration
local p = entity.object:get_pos()
local new_velo = {x=0, y=0, z=0}
@ -337,6 +374,7 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if ni == "air" then
if can_fly == true then
new_acce.y = 0
acce_y = acce_y - get_sign(acce_y) -- When going down, this will prevent from exceeding the maximum speed.
end
elseif ni == "liquid" then
if entity.terrain_type == 2 or entity.terrain_type == 3 then