Converting 3D LookVector to a 2D frame

I’m making a radar for a game and I’ve done all the basic things but I’m not good at math and don’t know how to show a players LookVector on the radar. I basically just want a line extending 10-20 studs from the middle of the playerdot in the direction they are looking at.

local DeltaPos = Camera.CFrame:PointToObjectSpace(RootPart.Position)
local DotPos = Vector2.new(DeltaPos.X + RADAR_SIZE / 2 + RADAR_PADDING, DeltaPos.Z + RADAR_SIZE / 2 + RADAR_PADDING)
local LookVector = RootPart.CFrame.LookVector
		
local X = math.clamp(DotPos.X, RADAR_PADDING, RADAR_SIZE + RADAR_PADDING) * RADAR_SCALE
local Y = math.clamp(DotPos.Y, RADAR_PADDING, RADAR_SIZE + RADAR_PADDING) * RADAR_SCALE

To create the player dot position all I do is UDim2.new(0, DotPos.X, 0, DotPos.Y)

image

In the same way you used CFrame:PointToObjectSpace(Vector3),
you can use CFrame:VectorToObjectSpace(Vector3) and disregard the Z component.

local RelativeLookVector = Camera.CFrame:VectorToObjectSpace(RootPart.CFrame.LookVector)
local DirectionOnMap =Vector2.new(RelativeLookVector.Y, RelativeLookVector.X))

Thank you, I’ll try this (word limitttttttt)

It points to the corner of my screen instead of showing where they’re looking
image

You’ll need to add the DirectionOnMap to the Dot’s position, since the direction is just a vector from (0, 0)

like this?

local DeltaPos = Camera.CFrame:PointToObjectSpace(RootPart.Position)
local DotPos = Vector2.new(DeltaPos.X + RADAR_SIZE / 2 + RADAR_PADDING, DeltaPos.Z + RADAR_SIZE / 2 + RADAR_PADDING)
local LookVector = RootPart.CFrame.LookVector
		
local X = math.clamp(DotPos.X, RADAR_PADDING, RADAR_SIZE + RADAR_PADDING) * RADAR_SCALE
local Y = math.clamp(DotPos.Y, RADAR_PADDING, RADAR_SIZE + RADAR_PADDING) * RADAR_SCALE
		
local Test1 = Camera.CFrame:VectorToObjectSpace(RootPart.CFrame.LookVector)
local Test2 = Vector2.new(Test1.Y, Test1.X)
local Test3 = Vector2.new(X, Y) + Test2
1 Like

This seems to be working thank you for the help!

I do have a question though why do the lines sometimes get smaller when the players turn?

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