Custom renderer entity positioning

  1. What do you want to achieve?
    Currently I am making a custom renderer of sorts using raycasts, similar to stuff like the original Doom and Wolfenstein 3D.

  2. What is the issue?
    The issue comes from the side of rendering entities, I have no idea how to accurately position them on the X axis of the screen. Currently I got an angle between the entity and the camera, but it only does positive values, which is where the issue resides, since I don’t know if the entity is to the left or right.

  3. What solutions have you tried so far?
    I tried looking for a solution online, didn’t find anything.

Here’s the angle/direction code:

local observerLook = (camera.CFrame.LookVector * Vector3.new(1,0,1)).Unit
local targetDirection = ((entities[index].Position * Vector3.new(1,0,1)) - (origin * Vector3.new(1,0,1))).Unit -- direction from observer to target
local angle = math.acos(observerLook:Dot(targetDirection))

The value returned is always positive, so I can’t know if the entity is to the right or left

Here’s an approach I like to use that abstracts some of the math away. This assumes that origin is the character position.

local entityPos = entities[index].Position
local lookAt = CFrame.lookAt(entityPos, origin, Vector3.yAxis) -- Entity looking at origin
local rX, rY, rZ = lookAt:ToOrientation() -- Get rotational components
local entityCF = CFrame.new(entityPos) * CFrame.Angles(0, rY, 0) -- Rotate about the Y-axis to face origin

I should have mentioned that the entity is rendered with an ImageLabel, so looking at your code it doesn’t seem like it will work. I need to know the angle so I could position it correctly from left to right of the screen.

After a bit of tinkering I realized I can use the orientation part of your example and then just subtract the orientation of the camera.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.