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