So just a few minutes ago I found a post stating that you can move a part left/right based on it’s orientation by multiplying its RightVector. I tried it out with UpVector but it says that UpVector cannot be assigned to. Can anybody help me out?
BTW here’s the code I’m using:
local runService = game:GetService("RunService")
local point = script.Parent
local cframeAmount = point.CFrame
local random = Random.new()
runService.Heartbeat:Connect(function()
local Outoffsetno = random:NextNumber(0, 2)
local chooseOperation = math.random(1, 2)
if chooseOperation == 1 then
point.CFrame.UpVector *= Outoffsetno
else
point.CFrame.UpVector *= Outoffsetno
end
task.wait(random:NextNumber(1, 2))
end)
UpVector is a unit Vector3 property of CFrame, and subsequently part of the CFrame matrix. You can do vector addition to a CFrame to get another CFrame. In your case it would look like this:
local runService = game:GetService("RunService")
local point = script.Parent
local cframeAmount = point.CFrame
local random = Random.new()
runService.Heartbeat:Connect(function()
local Outoffsetno = random:NextNumber(0, 2)
local chooseOperation = math.random(1, 2)
if chooseOperation == 1 then
point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno
else
point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno
end
task.wait(random:NextNumber(1, 2))
end)
That is why I did vector addition on the CFrame value. You can multiply a Vector3 by a scalar. You can also add a Vector3 to a CFrame. Since UpVector is a unit vector that is part of the CFrame matrix, adding it multiplied by a scalar gives the desired result.
You can see this by inserting a Part into workspace and doing the following:
Still doesn’t work, I tried just multiplying cframeAmount’s UpVector so that it will ALWAYS have to be near it’s origin CFrame. Even multiplying Outoffsetno by 0.25 didn’t help
when you do your addition of point.CFrame = point.CFrame + point.CFrame.UpVector * Outoffsetno, Outoffsetno is a scalar. This is why I told you to multiply it by another scalar, for which the example I provided was 0.5, and you subsequently tested 0.25. Based on your code, the maximum value of this offset scalar is 2, and multiplying it by 0.25 would give us 0.5 studs. Anyways, when you say that you want it to be near its origin CFrame, would I be right to assume the following:
That you want the parts to be located on this red line, and that you currently have it unintentionally offset? And are trying to move them by the blue line offsets?
Yes, that’s exactly what I want. The offset goes WAY MORE than it did before I implemented your solution
PS: I also want it to go lower, the code I sent in the original post had a typo and had 2 *
Can you post the entirety of your existing code so I can do some problem solving on it and reach the result you want? You can also opt to send me your .rbxl or .rbxlx file instead.