fgfbfrj
(HowBizzare)
November 10, 2021, 9:11pm
1
Like the title has described the problem, my character isn’t looking at the mouse position.
I used commonly used trigonometric function Atan2(), which returns me angles i need to know, but it seems like it doesn’t work. can somebody tell me what’s wrong?
The equation
script.LookAngle.Value = math.atan2(-Input.getMousePosition().X,-Input.getMousePosition().Y) * (180/math.pi)
Module
function HotkeyModule.getMousePosition()
return Vector2.new(Mouse.X,Mouse.Y)
end
CameraControl
Character:SetPrimaryPartCFrame(CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0,math.rad(script.Parent.InputControl.LookAngle.Value),0))
MamorruAlt
(MamorruAlt)
November 10, 2021, 9:29pm
2
try adding 90 degrees to the y axis
1 Like
fgfbfrj
(HowBizzare)
November 10, 2021, 9:36pm
4
Thanks for you help, i solved it myself
nuttolum
(nut)
November 10, 2021, 9:45pm
5
tell us and future readers how you solved it
fgfbfrj
(HowBizzare)
November 10, 2021, 10:44pm
6
Just trasnformed it into 3d vector and used the if statement to check if the Angle is smaller than zero so i can turn it back to a positive number.
I think you got it reversed:
math.atan2(-Input.getMousePosition().X,-Input.getMousePosition().Y)
Correct version:
math.atan2(-Input.getMousePosition().Y,-Input.getMousePosition().X)
Notice it’s
Y
then
X
, not the other way around.