Why is part not rotating correctly?

Goal

I’m currently working on a camera cutscene styled system, where the camera of the player is attached to a part, and the part rotates to match the end position and orientation.

Issue

I’m unsure why, but the camera part that the players camera follows isn’t in the correct position whilst rotating to fit the correct orientation. The orientation of both is the same in game, 0,-90,0. Here’s a video showing the issue.

image

Script

local args = {"Beginning Frame" = game.Workspace.Part1,["Ending Frame"] = game.Workspace.Part2}
local Beginning = game.Workspace["Camera Positions"][args["Beginning Frame"]];local End = game.Workspace["Camera Positions"][args["Ending Frame"]]
local tweenInfo = TweenInfo.new(5);local newPart 
if not game.Workspace:FindFirstChild("Camera Tween") then
	newPart = Instance.new("Part",workspace);newPart.Transparency = 1;newPart.CanCollide = false;newPart.Anchored = true;newPart.Name = "Camera Tween"
	newPart.CFrame = CFrame.new(Beginning.Position)
else
	newPart = game.Workspace["Camera Tween"]
end
local tweenPosition = game:GetService("TweenService"):Create(newPart,tweenInfo,{CFrame=CFrame.new(End.Position,End.Orientation)})
tweenPosition:Play()
1 Like

It seems to me that you are using the CFrame.new(Position, LookVector) constructor of the CFrame.

This constructor constructs the CFrame from a position, and a direction (vector it is supposed to look towards), not the orientation of the CFrame. You could just directly use End.CFrame instead of creating a new CFrame.

CFrame = End.CFrame

Alternatively, you could use CFrame.new(Position) * CFrame.Angles(radX, radY, radZ)

In CFrame.Angles, you construct a CFrame based on the angles in radians. And then by using * with the position CFrame you get a CFrame combined with the rotation and Position.

CFrame = CFrame.new(End.Position) * CFrame.Angles(math.rad(End.Orientation.X), math.rad(End.Orientation.Y), math.rad(End.Orientation.Z))

I also see that you’re tweening newPart and not the camera, is there an additional script tweening the camera to the newPart?

Yes, there is a script on the client that I fire to to attach the subject of the clients camera to.

It works! Just had to adjust certain bricks turn, thank you so much!

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