Currently I’m working on a hit indicator, which means it will create a 2D small Frame on where a gun’s hit. I use Bullet Holes as a standard, which positioned in the end on a casted ray.
I use WorldToScreenPoint to get the 2D position of the bullet hole such that I can position the small Frame. I also have a crosshair ImageLabel UI that follows the mouse, it’s parented to a Frame.
game:GetService("RunService").RenderStepped:Connect(function()
frame.Position = UDim2.new(0, mouse.X - script.Parent.AbsoluteSize.X / 2, 0, mouse.Y - script.Parent.AbsoluteSize.Y / 2)
end)
The half transparent part is the Frame, the crosshair is the ImageLabel.
I’m trying to put the small frames (mentioned above) inside the crosshair frame. However, the return of WorldToScreenPoint is only the the offset from the bottom left of the screen, let’s say it returned 800 and 400, 2 values representing X and Y respectively, how do I utilize this 2 numbers to relocate the small frame?
I tried to use multiply the values by 0.001 and set them as X and Y’s scale, however since the return is offset but not scale, it didn’t position correctly.
https://gyazo.com/63a568ef9b81b20b65984bdc82ef8c75
local vector = cam:WorldToScreenPoint(BulletPart.Position)
indicator.Position = UDim2.new(vector.X ,0, vector.Y, 0)
Do I have to do something with WorldToScreenPoint or locating the Frame?
FYI, I used to put the frames inside a ScreenGui, and their position would be 0, offsetX, 0, offsetY (0,800,0,400 for above example), it did work well since it’s parented inside a ScreenGui but not any Frames, however it’s not located inside the crosshair Frame, which is what I’m trying to achieve right now.