Get Player Y rotation

I think this is a pretty dumb question, but how do you get the players y rotation? I am trying to make a drone look in the direction of the player, by setting its rotation to the players rotation. I am currently just doing HRP.CFrame.Rotation.Y. My problem is that facing “forward” is the same value as facing “backward”, 0. Thus the drone looks backwards when it should not be.
Any help is appreciated

Could you provide us with some code?

local playerPos = player.char.HumanoidRootPart.Position

local playerYRotation = (player.char.HumanoidRootPart.CFrame.Rotation.Y)

desiredRotation = CFrame.new(drone.model.Position) * CFrame.Angles(0,playerYRotation,0)

Have you tried rotating the primary part of the drone.model to face the correct direction? If you don’t have a primary part, you should make/set one for the model and make sure it faces the correct way.

Right now the drone is currently one part, it is not really a drone.

is the drone supposed to look to the player or look in the direction where the player is looking

look the direction the player is looking, but only rotating on the y axis.

well what happens after you run the code?

I don’t recommend reading directly from the rotation vector to retrieve the rotation information. In simple cases where the player can only rotate on 1 axis you can get away with it, but when you throw player pitch/yaw/roll into the rotation the number won’t be read correctly.

I recommend to have the drone rotate with lookvector. If you don’t want the drone pitching up and down, you can multiply the lookvector by 1,0,1 to get rid of the pitch component.

local myHumanoidRootCFrame: CFrame = CFrame()
local myDrone: Model = drone

local upVector: Vector3 = Vector3.new(0,1,0)

local function updateDroneLookCFrame()
    local myLookVector: Vector3 = myHumanoidRootCFrame.LookVector
    if math.abs(myLookVector.Y) < 1 then -- make sure you're not looking perfectly straight up or down
        local dronePos: Vector3 = drone.PrimaryPart.Position
        drone:PivotTo(CFrame.new(dronePos, dronePos + myLookVector * Vector3.new(1,0,1)))
    end    
end
1 Like

Thanks for the help, that worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.