Hey Devs, is there a way to change the only the first 3 arguments in cframe? I assume its by doing substractions,
Using CFrame - CFrame.P
will allow you to get only orientational value
For example,
Object.CFrame = CFrame.new(#, #, #) * (Object.CFrame - Object.CFrame.Position)
I dont want to change the angles tho i just want to change the item’s coordination x, y, z
cause i’m getting the cframe of a part
This keeps the Angle of the object as is, and only changes positional value
one way is by getting the orientation, and making a new cframe with it, like this:
local xr, yr, zr = cf:ToEulerAnglesYXZ()
local newCF = CFrame.new(newpos)*CFrame.Angles(xr,yr,zr)
Though the answer above by william is probably a better solution, a explanation of it is that you make a new CFrame with the new position, then apply the orientation of the previous cframe to it.
Honestly I’d use @WilliamAlezandro method. since none of the numbers in the orientation are being changed, it’ll stay the same before and after your movement.
Tween.TweenModel(Dummy, (Target.CFrame + Vector3.new(0, Dummy.PrimaryPart.Size.Y / 2, 0) * CFrame.Angles()), TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut))
Here’s my script i’m not putting arguments into angles so its erroring.
Tween.TweenModel(Dummy, (CFrame.new(Target.CFrame.Position) * CFrame.new(0, Dummy.PrimaryPart.Size.Y / 2, 0) * (Target.CFrame - Target.CFrame.Position)), TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut))
Still Argument #3 is missing error
It’d be helpful if you post the whole script here, and indicate where the error is coming from
local ReplicatedStorage = game.ReplicatedStorage
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game.ContextActionService
local Players = game.Players
local Framework = ReplicatedStorage.Framework
local Maid = require(Framework.Main.Maid)
local Tween = require(Framework.Util.Tween)
local PrimaryPart = require(Framework.Util.PrimaryPart)
local Player = Players.LocalPlayer
local GRID_SIZE = 4
local SPEED = 0.05
local DUMMY_TRANSPARENCY = 0.5
local Placement = {}
local PlacementMaid = Maid.new()
function Placement.StartPlacement(Studio, Item)
local Mouse = Player:GetMouse()
local Dummy = Item:Clone()
PlacementMaid:GiveTask(Dummy)
PrimaryPart:CreatePrimaryPart(Dummy, GRID_SIZE)
for index, instance in pairs(Dummy:GetDescendants()) do
if instance:IsA("BasePart") and instance ~= Dummy.PrimaryPart then
instance.Transparency = DUMMY_TRANSPARENCY
instance.CanCollide = false
elseif instance:IsA("Script") or instance:IsA("LocalScript") then
instance.Disabled = true
end
end
local CURRENT_ROTATION = 0
local function Rotate(_, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
CURRENT_ROTATION = CURRENT_ROTATION + 90
Dummy:SetPrimaryPartCFrame(Dummy.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(CURRENT_ROTATION), 0))
end
end
Mouse.Move:Connect(function()
local Target = Mouse.Target
local LastTarget
if Target and Target.Parent and Target.Parent.Name == "FloorGrids" and LastTarget ~= Target then
LastTarget = Target
Mouse.TargetFilter = Dummy
Dummy.Parent = Target
Tween.TweenModel(Dummy, (CFrame.new(Target.CFrame.Position) * CFrame.new(0, Dummy.PrimaryPart.Size.Y / 2, 0) * CFrame.Angles()), TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut))
end
end)
ContextActionService:BindAction("Rotate", Rotate, false, Enum.KeyCode.R)
end
function Placement.StopPlacement()
PlacementMaid:DoCleaning()
end
return Placement
Error coming from Line 55 when i added an empty CFrame.Angles it started erroring
My bad, you have to subtract Position from CFrame itself to retrieve Angles.
local ReplicatedStorage = game.ReplicatedStorage
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game.ContextActionService
local Players = game.Players
local Framework = ReplicatedStorage.Framework
local Maid = require(Framework.Main.Maid)
local Tween = require(Framework.Util.Tween)
local PrimaryPart = require(Framework.Util.PrimaryPart)
local Player = Players.LocalPlayer
local GRID_SIZE = 4
local SPEED = 0.05
local DUMMY_TRANSPARENCY = 0.5
local Placement = {}
local PlacementMaid = Maid.new()
function Placement.StartPlacement(Studio, Item)
local Mouse = Player:GetMouse()
local Dummy = Item:Clone()
PlacementMaid:GiveTask(Dummy)
PrimaryPart:CreatePrimaryPart(Dummy, GRID_SIZE)
for index, instance in pairs(Dummy:GetDescendants()) do
if instance:IsA("BasePart") and instance ~= Dummy.PrimaryPart then
instance.Transparency = DUMMY_TRANSPARENCY
instance.CanCollide = false
elseif instance:IsA("Script") or instance:IsA("LocalScript") then
instance.Disabled = true
end
end
local CURRENT_ROTATION = 0
local function Rotate(_, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
CURRENT_ROTATION = CURRENT_ROTATION + 90
Dummy:SetPrimaryPartCFrame(Dummy.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(CURRENT_ROTATION), 0))
end
end
Mouse.Move:Connect(function()
local Target = Mouse.Target
local LastTarget
if Target and Target.Parent and Target.Parent.Name == "FloorGrids" and LastTarget ~= Target then
LastTarget = Target
Mouse.TargetFilter = Dummy
Dummy.Parent = Target
Tween.TweenModel(Dummy, (CFrame.new(Target.CFrame.Position) * CFrame.new(0, Dummy.PrimaryPart.Size.Y / 2, 0) * (Target.CFrame - Target.CFrame.Position), TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut))
end
end)
ContextActionService:BindAction("Rotate", Rotate, false, Enum.KeyCode.R)
end
function Placement.StopPlacement()
PlacementMaid:DoCleaning()
end
return Placement
Yeah but this returns the angle still
Never mind it works! Thank you so much.