Modified collision detection to be based on velocity vector length rather than if the block you're touching is or is not air

This commit is contained in:
Guy Liner 2022-01-16 15:54:49 -05:00
parent aac55e9e38
commit 732296aa15
2 changed files with 3 additions and 5 deletions

View File

@ -88,14 +88,13 @@ function mcl_playerinfo:collision_detect(pos,player)
for placement,coord in pairs(around_player) do for placement,coord in pairs(around_player) do
local node = minetest.get_node(coord) local node = minetest.get_node(coord)
local distance = vector.distance(pos, coord) local distance = vector.distance(pos, coord)
local not_moving = vector.length(player:get_velocity()) < 3
-- How far is the player from the block in the given direction and -- How far is the player from the block in the given direction and
-- if the block is not air the player is colliding with it -- if the block is not air the player is colliding with it
--print(node.name) if vector.distance(pos, coord) < too_close and not_moving then
--print(distance)
if vector.distance(pos, coord) < too_close and node.name ~= "air" then
return false return false
--Should be able to detect when your head is touching a slab --Should be able to detect when your head is touching a slab
elseif distance < slab_too_close and distance > too_close and placement == "front_ofplayerplus" and node.name ~= "air" then elseif distance < slab_too_close and distance > too_close and not_moving and placement == "front_ofplayerplus" then
return false return false
end end
end end

View File

@ -175,7 +175,6 @@ minetest.register_globalstep(function(dtime)
--Check if the player should be sprinting --Check if the player should be sprinting
if not isNotColliding and ctrl.aux1 and ctrl.up and not ctrl.sneak then if not isNotColliding and ctrl.aux1 and ctrl.up and not ctrl.sneak then
print("uwu")
players[playerName]["shouldSprint"] = false players[playerName]["shouldSprint"] = false
elseif isNotColliding and players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then elseif isNotColliding and players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then
players[playerName]["shouldSprint"] = true players[playerName]["shouldSprint"] = true