How to only use Y-Axis to Rotate a Model With PivotTo

So, I’ve made a Tool, that if you Activate it, it creates a Wall on the Player’s Mouse Hit Position and with the Player’s Camera Rotation, like this:

-- Script

local Pos, CamCF = MouseLoc:InvokeClient(Player)

ClonedWall:SetPrimaryPartCFrame(CFrame.new(Pos + Vector3.new(0, 0.5, 0), Pos + Vector3.new(CamCF.lookVector.X, CamCF.lookVector.Y, CamCF.lookVector.Z)))
-- Local Script

local camera = game.Workspace.CurrentCamera

local Mouse = game.Players.LocalPlayer:GetMouse()

function Remote.OnClientInvoke()
	return Mouse.Hit.p, camera.CFrame
end

But I can’t make the Model Stand Up, a.k.a only rotate it’s Y-Axis to the Player’s Camera’s Y-Axis Rotation.

Video

1 Like

Hi,

Use PivotTo instead of SetPrimaryPartCFrame as it has been Deprecated,

Example:

workspace.Model:PivotTo(workspace.Model.WorldPivot * CFrame.Angles(0,10,0))
3 Likes
-- Script

local Pos, CamCF = MouseLoc:InvokeClient(Player)

ClonedWall:PivotTo(CFrame.new(Pos + Vector3.new(0, 0.5, 0), Pos + Vector3.new(CamCF.lookVector.X, 0.5, CamCF.lookVector.Z)))

Just use the global Y axis in a CFrame.lookat constructor

local goalCF = CFrame.lookAt(Pos + Vector3.new(0, 0.5, 0), Pos + CamCF.LookVector, Vector3.yAxis)
ClonedWall:PivotTo(goalCF)

This worked. Thank you guys so much!

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