View difference between Paste ID: g6fKt3wJ and Mwy939Sv
SHOW: | | - or go back to the newest paste.
1
local mods = peripheral.wrap "back"
2-
local targ = ...
2+
3
local function yaw_and_pitch(e)
4
    local x, y, z = e.x, e.y, e.z
5
    local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
6
    local yaw = math.atan2(-x, z)
7
    return math.deg(yaw), math.deg(pitch)
8
end
9
10
while true do
11
	for _, e in pairs(mods.sense()) do
12-
    local t = mods.getMetaByName(targ)
12+
	    if e.pitch ~= 0 and e.displayName == e.name then -- good heuristic for player detection 
13-
    if t then
13+
    	    local y, p = yaw_and_pitch(e)
14-
        local y, p = yaw_and_pitch(t)
14+
        	mods.look(y, p)
15-
        --mods.fire(y, p, 0.5)
15+
	    end
16-
        mods.launch(y, p, 1)
16+
	end
17-
    end
17+
18
end