improved code quality
This commit is contained in:
parent
9e1b0184c5
commit
cd62278336
|
@ -3,6 +3,7 @@ mcl_playerplus = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local player_velocity_old = {x=0, y=0, z=0}
|
local player_velocity_old = {x=0, y=0, z=0}
|
||||||
|
local player_position_old = {x=0, y=0, z=0}
|
||||||
local get_connected_players = minetest.get_connected_players
|
local get_connected_players = minetest.get_connected_players
|
||||||
local dir_to_yaw = minetest.dir_to_yaw
|
local dir_to_yaw = minetest.dir_to_yaw
|
||||||
local get_item_group = minetest.get_item_group
|
local get_item_group = minetest.get_item_group
|
||||||
|
@ -286,18 +287,20 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
if elytra.active then
|
if elytra.active then
|
||||||
mcl_player.player_set_animation(player, "fly")
|
mcl_player.player_set_animation(player, "fly")
|
||||||
local slowdown_mult = 0.2 -- amount of vel to take per sec
|
local slowdown_mult = 1 -- amount of vel to take per sec
|
||||||
local speedup_mult = 10 -- amount of speed to add based on look dir
|
local fall_speed = 40 -- amount to fall down per sec in nodes
|
||||||
|
local speedup_mult = 15 -- amount of speed to add based on look dir
|
||||||
local max_speed = 120
|
local max_speed = 120
|
||||||
local direction = player:get_look_dir()
|
local direction = player:get_look_dir()
|
||||||
local v = player:get_velocity()
|
local player_vel = player:get_velocity()
|
||||||
local direction_mult = clamp(-direction.y*2, -0.5, 0.5)
|
local direction_mult = clamp(-direction.y*2, -0.5, 0.5)
|
||||||
local speed_mult = clamp(elytra.speed + direction_mult * speedup_mult * dtime, -max_speed, max_speed)
|
|
||||||
speed_mult = speed_mult - slowdown_mult * speed_mult * dtime -- slow down
|
local speed_mult = elytra.speed + direction_mult * speedup_mult * dtime
|
||||||
|
speed_mult = speed_mult - slowdown_mult * dtime -- slow down
|
||||||
speed_mult = math.max(speed_mult, -1)
|
speed_mult = math.max(speed_mult, -1)
|
||||||
speed_mult = math.min(speed_mult, max_speed)
|
speed_mult = math.min(speed_mult, max_speed)
|
||||||
elytra.speed = speed_mult
|
elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it
|
||||||
vel = direction
|
new_vel = direction -- use the facing direction as a base
|
||||||
|
|
||||||
playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1)
|
playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1)
|
||||||
if elytra.rocketing > 0 then
|
if elytra.rocketing > 0 then
|
||||||
|
@ -323,18 +326,20 @@ minetest.register_globalstep(function(dtime)
|
||||||
playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra")
|
playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra")
|
||||||
end
|
end
|
||||||
|
|
||||||
vel = vector.multiply(vel, speed_mult)
|
new_vel = vector.multiply(new_vel, speed_mult)
|
||||||
vel = {
|
new_vel = {
|
||||||
x = clamp(vel.x, -max_speed, max_speed),
|
x = clamp(new_vel.x, -max_speed, max_speed),
|
||||||
y = clamp(vel.y, -max_speed, max_speed),
|
y = clamp(new_vel.y, -max_speed, max_speed),
|
||||||
z = clamp(vel.z, -max_speed, max_speed)}
|
z = clamp(new_vel.z, -max_speed, max_speed)}
|
||||||
|
|
||||||
-- slow the player down so less spongy movement by applying half the inverse vel
|
-- slow the player down so less spongy movement by applying half the inverse vel
|
||||||
-- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken
|
-- NOTE: do not set this higher than about 0.7 or the game will get the wrong vel and it will be broken
|
||||||
v = vector.multiply(v, -0.4)
|
-- this is far from ideal, but there's no good way to set_velocity on the player
|
||||||
player:add_velocity(v)
|
player_vel = vector.multiply(player_vel, -0.4)
|
||||||
vel.y = vel.y - (200 / math.max(speed_mult+1, 1)) * dtime
|
player:add_velocity(player_vel)
|
||||||
player:add_velocity(vel)
|
new_vel.y = new_vel.y - (400 / math.max(speed_mult, 2)) * dtime
|
||||||
|
new_vel.y = new_vel.y - fall_speed * dtime
|
||||||
|
player:add_velocity(new_vel)
|
||||||
end
|
end
|
||||||
|
|
||||||
if wielded_def and wielded_def._mcl_toollike_wield then
|
if wielded_def and wielded_def._mcl_toollike_wield then
|
||||||
|
@ -350,6 +355,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
player_velocity_old = player:get_velocity() or player:get_player_velocity()
|
player_velocity_old = player:get_velocity() or player:get_player_velocity()
|
||||||
|
player_position_old = player:get_pos()
|
||||||
|
|
||||||
|
|
||||||
-- controls right and left arms pitch when shooting a bow or blocking
|
-- controls right and left arms pitch when shooting a bow or blocking
|
||||||
|
|
Loading…
Reference in New Issue
Block a user