Greetings developers,
I’m looking for some help with turning a starfighter relative to the mouse position. (The more the mouse is away from the centre, the more it turns.)
Right now it just moves the starfighter to 0, 0, 0 with no rotation.
This is what I have in a LocalScript parented to a Gui that follows the mouse:
game["Run Service"].Heartbeat:Connect(function()
wait(0.1)
if inSeat then
game.ReplicatedStorage.RemoteEvents.StarfighterMouse:FireServer({tonumber(string.split(tostring(script.Parent.Position.X), ", ")[2]), tonumber(string.split(tostring(script.Parent.Position.Y), ", ")[2])}, {game.Players.LocalPlayer:GetMouse().ViewSizeX, game.Players.LocalPlayer:GetMouse().ViewSizeY})
end
end)
And I have this in a ServerScript parented to the starfighter:
game.ReplicatedStorage.RemoteEvents.StarfighterMouse.OnServerEvent:Connect(function(plr, mousePos, screenSize)
if script.Parent.StarfighterSeat.Occupant ~= nil then
if script.Parent.StarfighterSeat.Occupant.Parent.Name == plr.Name then
game.TweenService:Create(script.Parent.TweenValue, TweenInfo.new(0.1), {Value = CFrame.new(script.Parent:GetPrimaryPartCFrame().Position) * CFrame.Angles(
(math.rad((script.Parent:GetPrimaryPartCFrame().Rotation.X * mousePos[1] - (screenSize[1] / 2))) / 10),
(math.rad((script.Parent:GetPrimaryPartCFrame().Rotation.Y * mousePos[2] - (screenSize[2] / 2))) / 10),
0
)})
script.Parent:SetPrimaryPartCFrame(script.Parent.TweenValue.Value)
end
end
end)
Any help is appreciated.