I’m working on a light that realistically follows a player from where it is. To achieve this, I’m using (what should be) basic trig to calculate the desired angle for my Motor6D. However, since each dimension needs to be handled separately by the light (the clamp turns for the X and Z dimension and the light turns for the Y dimension), the math is coming out weirdly.
Below I’ve attached a video — the white lines are helper lines, the green line is where the light is currently pointing, and the blue line is where the light should ideally end up pointing.
If anyone could help me correct the math, I’d appreciate it.
local light = script.Parent
local spotlight = light.SpotLight
local clamp = light.Clamp
local clampBase = clamp.Base
local clampUp = clamp.Up
local clampRight = clamp.Right
local targetPosition = Vector3.new(0, 10, 0)
function clampToVector(vector3)
local vector = vector3 - clampBase.Position