forked from hkc/cc-stuff
1
0
Fork 0

wallhack: showing entity look direction

This commit is contained in:
Vftdan 2023-10-14 15:35:22 +03:00
parent 3e2835419d
commit d76ec0c5a0
1 changed files with 19 additions and 4 deletions

View File

@ -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,26 @@ 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].lookDot = canvas3d.addDot({ 0, 0, 0 }, 0, 2)
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].lookDot.setColor(0x004040FF)
else else
cache[id].cube.setColor(0xFFC0C0FF) cache[id].cube.setColor(0xFFC0C0FF)
cache[id].lookDot.setColor(0xFFC0C0FF)
end end
cache[id].cube.setAlpha(0x20) cache[id].cube.setAlpha(0x20)
cache[id].lookDot.setAlpha(0x10)
cache[id].cube.setDepthTested(false) cache[id].cube.setDepthTested(false)
cache[id].frame.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].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].lookDot.setPosition(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))