I’d like to know the best way to set the Y value of a model CFrame, seems easy but my brain isn’t working today & the game setup makes this difficult. (Appreciate any help)
Just need to set the Y value of a CFrame and nothing else (Not something like this)
I just want to set the Y Value while changing nothing else.
I’ve tried looking through the developer hub, but most solutions have depreciated vars or changed the X, Y & Z
Here is the current code I’m working with
(This is somewhat using OOP, I’m using the self variable, the way the game is formatted and the scripts I’m working with won’t allow the simple: CFrame.Y = or Position.Y = )
local Structure = require(game.ReplicatedStorage.Classes.Structures.Structure)
local Dock = Structure:Extend(script.Name)
local sealevel = game.ReplicatedStorage.Constants.OceanSurfaceY.Value
function Dock:OnNew()
self.PrimaryPart = self.Base.PrimaryPart
if self.PrimaryPart then
print(self.PrimaryPart.Name)
if self.PrimaryPart.Name == "Wood" then
self.Base:SetPrimaryPartCFrame(CFrame.new(self.PrimaryPart.CFrame, sealevel + 0.5 ,self.PrimaryPart.CFrame.Z) * self.Base.PrimaryPart.CFrame:toOrientation() )
end
end
end
return Dock
local function scf(cframe, xyz)
if xyz.x ~= 0 then
return CFrame.new(xyz.x, cframe.y, cframe.z)
end
if xyz.y ~= 0 then
return CFrame.new(cframe.x, xyz.y, cframe.z)
end
if xyz.z ~= 0 then
return CFrame.new(cframe.x, cframe.y, xyz.z)
end
end
part.CFrame = scf(part.CFrame, Vector3.new(0, 5, 0))
Your right just had to format it I’ll test it now:
local Structure = require(game.ReplicatedStorage.Classes.Structures.Structure)
local Dock = Structure:Extend(script.Name)
local sealevel = game.ReplicatedStorage.Constants.OceanSurfaceY.Value
function Dock:OnNew()
self.PrimaryPart = self.Base.PrimaryPart
if self.PrimaryPart then
print(self.PrimaryPart.Name)
if self.PrimaryPart.Name == "Wood" then
---self.Base:SetPrimaryPartCFrame(CFrame.new(self.PrimaryPart.CFrame, sealevel + 0.5 ,self.PrimaryPart.CFrame.Z) * self.Base.PrimaryPart.CFrame:toOrientation() )
print("Is Past")
self.PrimaryPart = Dock:scf(self.PrimaryPart.CFrame, Vector3.new(0, 5, 0))
end
end
end
function Dock:scf(cframe, xyz)
if xyz.x ~= 0 then
return CFrame.new(xyz.x, cframe.y, cframe.z)
end
if xyz.y ~= 0 then
return CFrame.new(cframe.x, xyz.y, cframe.z)
end
if xyz.z ~= 0 then
return CFrame.new(cframe.x, cframe.y, xyz.z)
end
end
return Dock
There is a problem with that, so you see basically this is a placement, I can’t use the old self.PrimaryPart.CFrame.X as the reference is different due to this being global it grabs the model in Replicated storage, so it would set the X to however the old one is, which isn’t ideal because you are supposed to be placing the model. (Prob should’ve clarified that)
local currentCFrame = self.Base:GetPivot()
local yOffset = sealevel + 0.5 - currentCFrame.Position.Y
local newCFrame = currentCFrame + vector3.new(0, yOffset, 0)
self.Base:PivotTo(newCFrame)
or
local currentCFrame = self.Base:GetPivot()
local position = Vector3.new(currentCFrame.Position.X, sealevel + 0.5, currentCFrame.Position.Z)
local newCFrame = currentCFrame.Rotation + position
self.Base:PivotTo(newCFrame)