Skip to content

Commit b16d25c

Browse files
author
cheapie
committed
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.
1 parent a5ca8f1 commit b16d25c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

controller.lua

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ local players_on_controller = {}
1414

1515
local last_seen_inputs = {}
1616

17+
local function removeEntity(pos)
18+
local entitiesNearby = minetest.get_objects_inside_radius(pos,0.5)
19+
for _,i in pairs(entitiesNearby) do
20+
if i:get_luaentity() and i:get_luaentity().name == "digistuff:controller_entity" then
21+
i:remove()
22+
end
23+
end
24+
end
25+
1726
local function process_inputs(pos)
1827
local meta = minetest.get_meta(pos)
1928
local hash = minetest.hash_node_position(pos)
@@ -36,14 +45,6 @@ local function process_inputs(pos)
3645
players_on_controller[hash] = nil
3746
return
3847
end
39-
local distance = vector.distance(pos,player:get_pos())
40-
if distance > 1 then
41-
digiline:receptor_send(pos,digiline_rules,meta:get_string("channel"),"player_left")
42-
minetest.get_meta(pos):set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
43-
player:set_physics_override({speed = 1,jump = 1,})
44-
players_on_controller[hash] = nil
45-
return
46-
end
4748
local inputs = player:get_player_control()
4849
inputs.pitch = player:get_look_vertical()
4950
inputs.yaw = player:get_look_horizontal()
@@ -71,11 +72,15 @@ end
7172
local function release_player(pos)
7273
local hash = minetest.hash_node_position(pos)
7374
local player = minetest.get_player_by_name(players_on_controller[hash])
74-
if player then
75-
player:set_physics_override({speed = 1,jump = 1,})
76-
player:set_pos(vector.add(pos,vector.new(0.25,0,0.25)))
75+
if player and player:get_properties()._is_gamecontroller then
76+
local parent = player:get_attach()
77+
print(dump(parent:get_properties()))
78+
if parent then
79+
player:set_detach()
80+
end
7781
minetest.chat_send_player(players_on_controller[hash],"You are now free to move.")
7882
end
83+
removeEntity(pos)
7984
local meta = minetest.get_meta(pos)
8085
meta:set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
8186
last_seen_inputs[players_on_controller[hash]] = nil
@@ -92,8 +97,8 @@ local function trap_player(pos,player)
9297
return
9398
else
9499
players_on_controller[hash] = newname
95-
player:set_pos(vector.add(pos,vector.new(0,-0.4,0)))
96-
player:set_physics_override({speed = 0,jump = 0,})
100+
local entity = minetest.add_entity(pos,"digistuff:controller_entity")
101+
player:set_attach(entity,"",vector.new(0,0,0),vector.new(0,0,0))
97102
minetest.chat_send_player(newname,"You are now using a digilines game controller. Right-click the controller again to be released.")
98103
local meta = minetest.get_meta(pos)
99104
meta:set_string("infotext","Digilines Game Controller\nIn use by: "..newname)
@@ -202,6 +207,16 @@ minetest.register_node("digistuff:controller_programmed", {
202207
},
203208
})
204209

210+
minetest.register_entity("digistuff:controller_entity",{
211+
initial_properties = {
212+
visual = "sprite",
213+
physical = false,
214+
collisionbox = {0,0,0,0,0,0,},
215+
textures = {"digistuff_transparent.png",},
216+
_is_gamecontroller = true,
217+
},
218+
})
219+
205220
local acc_dtime = 0
206221

207222
minetest.register_globalstep(function(dtime)

docs/game-controller.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ When a player leaves a controller, the string "player_left" is sent.
55
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:
66
* The controller is moved or removed
77
* The player leaves the game
8-
* The player is teleported away from the controller
98
* The controller receives the string "release" on its digilines channel

textures/digistuff_transparent.png

526 Bytes
Loading

0 commit comments

Comments
 (0)