Code doesn't print anything when looking to the left of or behind a part

I’m about a month or so into scripting and I’m not very great at explaining things so please bear with me.

I’m trying to write a script that will print the dot positions of a camera’s look vector and a block’s look vector, right vector, and up vector if the camera is facing away from the block (otherwise, just don’t print anything at all.)

Below is said script:

local block = game.Workspace:WaitForChild("block")
local cam = workspace.CurrentCamera

while wait(1) do
	local camV = cam.CFrame.LookVector
	local bl, br, bu = block.CFrame.LookVector, block.CFrame.RightVector, block.CFrame.UpVector
	local dotl, dotr, dotu = camV:Dot(bl), camV:Dot(br), camV:Dot(bu)
	if dotl <= (-0.54) or dotr <= (-0.54) or dotu <= (-0.54) then
		print(dotl)
		print(dotr)
		print(dotu)
	end
end

The script works fine and prints the dots when you’re looking at the face of the block, the right of the block, and above the block. However, if you look at the left of the block or behind the block, the script doesn’t print anything at all. I’m assuming it’s because looking at the left or back of the block counts as facing away from it to the script.

I’ve tried using a raycast from the camera’s position to the block’s position and I’ve also tried switching up the numbers and adding additional conditions to the if statement, however, none of them worked and some even resulted in nothing happening at all. I’ve looked through the forums for some answers but I couldn’t find any answers.

I would REALLY appreciate any answers.

What are you trying to do with this script when you get these values?

If you describe what you are trying to accomplish in game (like a direction finder or an arrow to point the direction to the block using a GUI but only when looking away from it) then someone else may have a better understanding of the problem and be able to solve it for you.

This script is a testing script for a game in which objects move if you’re not facing them. I’m using print to see how I can get that idea to work.

Did a bit of searching and found this. Not sure if it has anything you can use though…

Sorry, this doesn’t really help. Thank you, though.

I found an answer from Moonvane.

2 Likes

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