You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I am making a minigame where you swim as a fish and you slowly evolve to become stronger.
I need to make the fish look towards the mouse so I could move it.
What is the issue? Include screenshots / videos if possible!
The sensitivity was weird i tried changing it and it just wouldn’t work
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried using math.atan2 and math.deg, but i just couldn’t get it perfect
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local frame = fish
local PosDiff = Vector2.new(y,x)
local DiffAngle = math.atan2(PosDiff.X, PosDiff.Y)
fish.Rotation = math.deg(DiffAngle + math.pi)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local mouse = player:GetMouse()
local frame = script.Parent
mouse.Move:Connect(function()
local mouseX = mouse.X
local mouseY = mouse.Y
frame.Rotation = "" --change to how you want to calculate rotation
end)
From an algorithm standpoint, it seems solid. You’re calculating the difference between the subject (fish) and target (mouse) position, then chucking that into math.atan2, turning the result into degrees and putting it into GuiObject.Rotation. What’s the weirdness you’re seeing? Maybe a screen recording will help describe the problem. It also helps if you provide all your code, including context.
I sorta assumed that since the variable name was PosDiff, implying you were doing something like fish.Position - mouse.Position. Also double check your (y, x) there, it’s likely that needs to be (x, y).
local frame = fish
local PosDiff = fish.AbsolutePosition - Vector2.new(x,y)
local DiffAngle = math.atan2(PosDiff.Y, PosDiff.X)
fish.Rotation = math.deg(DiffAngle)
Just chucked than in, it works better but its still weird.
You forgot to mention you weren’t doing this in screen space, but rather on a SurfaceGui in 3D space. You need to translate the mouse’s 3D position into a similar 2D position in relation to the SurfaceGui. There’s a number of ways to do this, but maybe you should try testing this on a screen-space UI rather than on a part.