forked from hkc/cc-stuff
wallhack: showing entity look direction
This commit is contained in:
parent
3e2835419d
commit
59e404f9e9
|
@ -1,20 +1,27 @@
|
||||||
return function()
|
return function()
|
||||||
local playerLookVector = nil
|
local playerLookVector = nil
|
||||||
|
|
||||||
local function updateLookVector()
|
local function getEntityLookVector(entity)
|
||||||
-- yaw:
|
-- yaw:
|
||||||
-- 0 => positive Z
|
-- 0 => positive Z
|
||||||
-- 90 => negative X
|
-- 90 => negative X
|
||||||
-- pitch:
|
-- pitch:
|
||||||
-- 0 => forward
|
-- 0 => forward
|
||||||
-- 90 => down
|
-- 90 => down
|
||||||
local yawr = math.rad(player.yaw)
|
if entity == nil or entity.yaw == nil or entity.pitch == nil then
|
||||||
local pitchr = math.rad(player.pitch)
|
return {0, 0, 0, x = 0, y = 0, z = 0}
|
||||||
|
end
|
||||||
|
local yawr = math.rad(entity.yaw)
|
||||||
|
local pitchr = math.rad(entity.pitch)
|
||||||
local cosPitch = math.cos(pitchr)
|
local cosPitch = math.cos(pitchr)
|
||||||
local x = cosPitch * -math.sin(yawr)
|
local x = cosPitch * -math.sin(yawr)
|
||||||
local z = cosPitch * math.cos(yawr)
|
local z = cosPitch * math.cos(yawr)
|
||||||
local y = -math.sin(pitchr)
|
local y = -math.sin(pitchr)
|
||||||
playerLookVector = {x, y, z, x = x, y = y, z = z}
|
return {x, y, z, x = x, y = y, z = z}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function updateLookVector()
|
||||||
|
playerLookVector = getEntityLookVector(player)
|
||||||
return playerLookVector
|
return playerLookVector
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,18 +75,27 @@ return function()
|
||||||
cache[id].cube.setSize(0.5, 0.5, 0.5)
|
cache[id].cube.setSize(0.5, 0.5, 0.5)
|
||||||
cache[id].frame = canvas3d.addFrame({ 0, 0, 0 })
|
cache[id].frame = canvas3d.addFrame({ 0, 0, 0 })
|
||||||
cache[id].text = cache[id].frame.addText({ 0, 0 }, "")
|
cache[id].text = cache[id].frame.addText({ 0, 0 }, "")
|
||||||
|
cache[id].lookLine = canvas3d.addLine({ 0, 0, 0 }, { 0, 0, 0 }, 2, 0)
|
||||||
end
|
end
|
||||||
local entityFront = toFrontCoords(entity)
|
local entityFront = toFrontCoords(entity)
|
||||||
|
local entityLook = getEntityLookVector(entity)
|
||||||
|
local entityLookEnd = vec3Add(entityFront, entityLook)
|
||||||
if entityFront.flipped then
|
if entityFront.flipped then
|
||||||
cache[id].cube.setColor(0x004040FF)
|
cache[id].cube.setColor(0x004040FF)
|
||||||
|
cache[id].lookLine.setColor(0x004040FF)
|
||||||
else
|
else
|
||||||
cache[id].cube.setColor(0xFFC0C0FF)
|
cache[id].cube.setColor(0xFFC0C0FF)
|
||||||
|
cache[id].lookLine.setColor(0xFFC0C0FF)
|
||||||
end
|
end
|
||||||
cache[id].cube.setAlpha(0x20)
|
cache[id].cube.setAlpha(0x20)
|
||||||
|
cache[id].lookLine.setAlpha(0x10)
|
||||||
cache[id].cube.setDepthTested(false)
|
cache[id].cube.setDepthTested(false)
|
||||||
cache[id].frame.setDepthTested(false)
|
cache[id].frame.setDepthTested(false)
|
||||||
|
cache[id].lookLine.setDepthTested(false)
|
||||||
cache[id].cube.setPosition(entityFront.x - 0.25, entityFront.y - 0.25, entityFront.z - 0.25)
|
cache[id].cube.setPosition(entityFront.x - 0.25, entityFront.y - 0.25, entityFront.z - 0.25)
|
||||||
cache[id].frame.setPosition(entityFront.x, entityFront.y, entityFront.z)
|
cache[id].frame.setPosition(entityFront.x, entityFront.y, entityFront.z)
|
||||||
|
cache[id].lookLine.setPoint(1, entityFront.x, entityFront.y, entityFront.z)
|
||||||
|
cache[id].lookLine.setPoint(2, entityLookEnd.x, entityLookEnd.y, entityLookEnd.z)
|
||||||
cache[id].text.setAlpha(0xFF)
|
cache[id].text.setAlpha(0xFF)
|
||||||
if player.isSneaking then
|
if player.isSneaking then
|
||||||
cache[id].text.setText(entity.name .. "\n" .. textutils.serialize(entity))
|
cache[id].text.setText(entity.name .. "\n" .. textutils.serialize(entity))
|
||||||
|
|
Loading…
Reference in New Issue