Hi, I’m Eli. I was working on another game of mine, I make them just for fun. I want a script so I can make a frame point to the money bag a player is holding. I’ve tried searching google and couldn’t find anything except for “How would I make a frame face another?” Any help would be appreciated.
WorldToScreenPoint will probably be what you’re looking for, you just need to feed the money bag’s position.
2 Likes
Okay, I’ll look into it. Thanks
You can use WorldToScreenPoint
to get the moneybag’s position on the player’s screen, then you’ll use math.atan2
to get the angle between the frame and the moneybag’s position on the screen, then apply it to the frame’s rotation:
local pos = workspace.CurrentCamera:WorldToScreenPoint(moneybag.Position) -- find the position on-screen
local f = -- your frame
local a = f.AbsolutePosition -- find the absolute position of the frame on-screen (not relative to any GuiObjects)
local angle = math.deg(math.atan2((pos.y - a.y), (pos.x - a.x))) -- find the angle and convert it from radians to degrees
f.Rotation = angle -- apply the rotation
4 Likes
Thank for the solution, but one more thing. Is it possible to make it so that it would size bigger for the farther/shorter away it is?
You’ll have to get the distance between the two vectors then size the frame based on the distance:
local dist = (pos - a).Magnitude -- gets the distance
local originalsize = -- original size of the frame (or default)
local s = dist * somefactor
f.Size = originalsize + UDim2.new(0, s, 0, s)
With this, the size increases when you’re farther away
1 Like