I want to make the player rotate towards the mouse using a body gyro. So what would I need to set the gyro’s Cframe to make it rotate towards the players mouse only on the Y rotation.
I have done a lot of research but I could not find any working formula so if there is one already can you send its link.
By the way, use the new CFrame.lookAt() function instead. You could just get the direction vector, and then flatten it to 2D space, and then use it to create a rotation CFrame:
local direction = mouse.Hit.Position - humanoidRootPart.Position
local flattenedDirection = (direction * Vector3.new(1, 0, 1)).Unit
local rotationCFrame = CFrame.lookAt(Vector3.new(), flattenedDirection)
Actually you don’t need the torso position for BodyGyros, since it just uses the rotational data of CFrame. And from my reply, I don’t need to .Unit the multiplied vector. So basicly the final code is this:
local direction = mouse.Hit.Position - humanoidRootPart.Position -- Get direction
direction *= Vector3.new(1, 0 ,1) -- Flatten direction
bodyGyro.CFrame = CFrame.lookAt(Vector3.new(), direction) -- Turn into CFrame