It sounds like you’re trying to create a minimap using a viewport frame, but the rotation is not working correctly. Your code snippet suggests that you’re trying to adjust the camera.CFrame to look at a specific position while considering the orientation of the root object. However, it seems there might be an issue with how you’re calculating the rotation.
If your goal is to create a top-down minimap that follows the player’s root orientation, you can adjust the rotation using the player’s orientation in the X-Z plane (yaw). Here’s how you might modify your code:
luaCopy code
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local camera = script.Parent.ViewportFrame.Camera
local root = player.Character:WaitForChild("HumanoidRootPart")
RunService.RenderStepped:Connect(function()
local yaw = math.rad(root.Orientation.Y) -- Convert to radians
camera.CFrame = CFrame.lookAt(root.Position + Vector3.new(0, 500, 0), root.Position) * CFrame.Angles(0, yaw, 0)
end)
In this code, I’ve assumed that you want to capture the rotation around the Y-axis (yaw) of the player’s root part and apply it to the minimap camera. The CFrame.Angles(0, yaw, 0) part handles this rotation.
Make sure that the root part of the player’s character is correctly named “HumanoidRootPart,” and ensure that the player’s character is loaded and present in the game before using it.
Keep in mind that this code snippet only addresses the rotation issue you mentioned. You might need to adjust other aspects of your minimap code to ensure it functions correctly and follows the player’s movement and orientation accurately.