I try to recreate the compass from Skyrim in Roblox and I stumbled upon a problem regarding quest icons.
I have already programmed the directions of the world and now I struggle to program quest markers. I have waypoints on the map and count angle between the player and said waypoint and then I try to place the marker in a right place of the compass. Nevertheless, the quest icons are shown in wrong places.
Here is the code for the general compass:
while true do
local delta = wait(1/60)
local look = camera.CoordinateFrame.lookVector
local look = Vector3.new(look.x, 0, look.z).unit
local lookY = math.atan2(look.z, look.x)
--print("Look", look)
local difY = restrictAngle(lookY - lastY)
lookY = restrictAngle(lastY + difY*delta*smoothness)
lastY = lookY
PositionIcons(look)
for unit, rot in pairs(units) do
rot = restrictAngle(lookY - rot)
if math.sin(rot) > 0 then
local cosRot = math.cos(rot)
local cosRot2 = cosRot*cosRot
unit.Visible = true
unit.Position = UDim2.new(0.5 + cosRot*0.6, unit.Position.X.Offset, 0, 3)
--print(unit, unit.Position)
else
unit.Visible = false
end
end
end
Here is the function to place the icons in the compass GUI:
local function PositionIcons(look)
for WaypointIcon, WaypointPosition in pairs(WaypointPositions) do
local difWaypoint = math.acos(WaypointPosition:Dot(look)/(WaypointPosition.Magnitude * look.Magnitude))
local lookY = math.atan2(look.z, look.x)
local rot = restrictAngle(lookY - difWaypoint)
if math.sin(rot) > 0 then
local cosRot = math.cos(rot)
WaypointIcon.Visible = true
WaypointIcon.Position = UDim2.new(0.5 + cosRot*0.6, 0, 0, 0)
end
end
end
The icon for GasStation is shown properly but as you can see the shop icon is on the right, while it should be on the left. Book and sign seem to be close to GasStation but they are far away on the right.