I have this model here:
And the pointer part.
I need to rotate this pointer around the center of the model (the center of the white wheel) and make it face the mouse on the Z axis.
This is my desired effect, with the rotating pointer being controlled by the mouse of course.
https://gyazo.com/219061d5c687380f9078279a1c56c5dc
I tried setting the Z CFrame on the pointer to mouse.Hit.Z, rotating around the center by making the pointer a model with another part to offset it but to no luck.
I’m definitely not good with CFrame math and i’ll need your help. Thank you very much.
Hi, I’d like to help you with this issue, but could we re-iterate over the question at hand. From what I understand you’re wanting the Hand to rotate at that fixed point in coordination to where the mouse is?
Yep, I want it to point to where the mouse is on screen.
Alright, give me a few seconds and i’ll make a template in studio. Could you give me the proportions of each object? Preferably the faces, and such.
If you’re working with mesh parts, you could remove the mesh ids and send me the model. Would help me get the right proportions with ease.
I got it to rotate around the origin point using
model.Pointer.CFrame = model.Pointer.Part.CFrame * CFrame.Angles(0, 0, math.rad(i * 2)) * CFrame.new(1, -10, 0)
.
Now all thats left is making it point to the mouse cursor
That’s the fun part I had that working a while ago. However the angle between mouse pos and center pos is giving me troubles, I have it rotating on the right hand side, but reflecting it seems almost impossible
https://gyazo.com/3cf57b75e752938a736d19235431e5e8
heres what i did, im only a few steps away from completing it
seems like i have the same problem as well
Here’s how far I’ve come
https://gyazo.com/23a7e3d9ffb8948d43ce443430421441
The angle is not quite right but almost there.
I hope you find a solution soon
Actually, couldn’t you just multiply the CFrame by CFrame.Angles(0, 0, math.rad(90))
?
Close, however I did figure it out I think.
local function ConvertToVec2(Vector)
local screenSize = Camera.ViewportSize
Vector = (Vector2.new(Vector.X, Vector.Y) - screenSize/2) * (2/screenSize)
return Vector3.new(Vector.X, -Vector.Y, 0)
end
game:GetService("RunService").RenderStepped:Connect(function()
local CenterPos = ConvertToVec2(Camera:WorldToScreenPoint(Center))
local Position = ConvertToVec2(UIS:GetMouseLocation())
local Difference = Position - CenterPos
local Angle = math.atan(Difference.X/Difference.Y)
if Position.Y > CenterPos.Y then
Angle = Angle + math.rad(180)
end
Clock.Pointer.CFrame = CFrame.new(Center) * CFrame.fromAxisAngle(Vector3.FromNormalId(Enum.NormalId.Front), Angle) * CFrame.new(0, -Clock.Pointer.Size.Y/2, 0)
end)
Sorry about all the print statements, used it for testing and forgot to remove.
That’s a lot more complicated than I thought. Thank you so much!
I’d just like to point out, that the Center variable is a WorldPosition of an Attachment. You can change it as needed.
https://gyazo.com/1643c2706aaf0329f933e61d138dbd2d
Also I took the liberty to make it Relative to the screen size etc.
I’m getting quiet a few errors on my side.
I assume Camera is workspace.CurrentCamera
? It throws Unable to cast Instance to Vector3
if i set the camera like that.
local UIS = game:GetService(“UserInputService”)
local Camera = workspace.CurrentCamera
local Center = Model.BigWheel.Attachment.WorldPosition
Those where the extra variables I had. The reasoning behind me using an Attachment was for a fixed location relative to the big wheel except it had a Position of 0, 0, -10 studs placing it 10 studs infront of the BigWheel
Alright, it works perfectly now. Thank you so much. I would have never figured it out myself!