Convert game controller to use entity attachment instead of a physics override

This should make it get along better with other mods that affect physics overrides, and also prevent the "walking in place" when using it.
This commit is contained in:
cheapie 2021-02-21 18:36:09 -06:00
parent a5ca8f19b7
commit b16d25c828
3 changed files with 28 additions and 14 deletions

@ -14,6 +14,15 @@ local players_on_controller = {}
local last_seen_inputs = {} local last_seen_inputs = {}
local function removeEntity(pos)
local entitiesNearby = minetest.get_objects_inside_radius(pos,0.5)
for _,i in pairs(entitiesNearby) do
if i:get_luaentity() and i:get_luaentity().name == "digistuff:controller_entity" then
i:remove()
end
end
end
local function process_inputs(pos) local function process_inputs(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
@ -36,14 +45,6 @@ local function process_inputs(pos)
players_on_controller[hash] = nil players_on_controller[hash] = nil
return return
end end
local distance = vector.distance(pos,player:get_pos())
if distance > 1 then
digiline:receptor_send(pos,digiline_rules,meta:get_string("channel"),"player_left")
minetest.get_meta(pos):set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
player:set_physics_override({speed = 1,jump = 1,})
players_on_controller[hash] = nil
return
end
local inputs = player:get_player_control() local inputs = player:get_player_control()
inputs.pitch = player:get_look_vertical() inputs.pitch = player:get_look_vertical()
inputs.yaw = player:get_look_horizontal() inputs.yaw = player:get_look_horizontal()
@ -71,11 +72,15 @@ end
local function release_player(pos) local function release_player(pos)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
local player = minetest.get_player_by_name(players_on_controller[hash]) local player = minetest.get_player_by_name(players_on_controller[hash])
if player then if player and player:get_properties()._is_gamecontroller then
player:set_physics_override({speed = 1,jump = 1,}) local parent = player:get_attach()
player:set_pos(vector.add(pos,vector.new(0.25,0,0.25))) print(dump(parent:get_properties()))
if parent then
player:set_detach()
end
minetest.chat_send_player(players_on_controller[hash],"You are now free to move.") minetest.chat_send_player(players_on_controller[hash],"You are now free to move.")
end end
removeEntity(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext","Digilines Game Controller Ready\n(right-click to use)") meta:set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
last_seen_inputs[players_on_controller[hash]] = nil last_seen_inputs[players_on_controller[hash]] = nil
@ -92,8 +97,8 @@ local function trap_player(pos,player)
return return
else else
players_on_controller[hash] = newname players_on_controller[hash] = newname
player:set_pos(vector.add(pos,vector.new(0,-0.4,0))) local entity = minetest.add_entity(pos,"digistuff:controller_entity")
player:set_physics_override({speed = 0,jump = 0,}) player:set_attach(entity,"",vector.new(0,0,0),vector.new(0,0,0))
minetest.chat_send_player(newname,"You are now using a digilines game controller. Right-click the controller again to be released.") minetest.chat_send_player(newname,"You are now using a digilines game controller. Right-click the controller again to be released.")
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("infotext","Digilines Game Controller\nIn use by: "..newname) meta:set_string("infotext","Digilines Game Controller\nIn use by: "..newname)
@ -202,6 +207,16 @@ minetest.register_node("digistuff:controller_programmed", {
}, },
}) })
minetest.register_entity("digistuff:controller_entity",{
initial_properties = {
visual = "sprite",
physical = false,
collisionbox = {0,0,0,0,0,0,},
textures = {"digistuff_transparent.png",},
_is_gamecontroller = true,
},
})
local acc_dtime = 0 local acc_dtime = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)

@ -5,5 +5,4 @@ When a player leaves a controller, the string "player_left" is sent.
In addition to right-clicking the controller in use to stop using it, the following will also cause a player to stop using the controller: In addition to right-clicking the controller in use to stop using it, the following will also cause a player to stop using the controller:
* The controller is moved or removed * The controller is moved or removed
* The player leaves the game * The player leaves the game
* The player is teleported away from the controller
* The controller receives the string "release" on its digilines channel * The controller receives the string "release" on its digilines channel

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B