It started to stay up by itself without being anchored or welded (still not sure how). Thanks for the suggestion though! Edit: Like yes35go just said, it’s the LinearVelocity combined with the AngularVelocity that makes the part anchored.
You could unanchor the part, then on a Heartbeat loop set the LinearVelocity
to Vector3.new(0, 0, 0)
. This way it will keep the part still.
For using CFrame/TweenService, you’re going to have to ditch CFrame and TweenService and move directly to AngularVelocity
. You could use TweenService for AngularVelocity, but what I would do instead is constantly set the AngularVelocity
every Heartbeat using Perlin noise.
I’ve been playing around with AngularVelocity and just got it to spin. I’ll update more in a bit.
By the way, to create a “noisy” number, use math.noise
.
Why not just weld the players HumanoidRootPart to the cube? If I’m correct, welds make the orientation of Part0
as Part1
s.
He wants the character to not be pinned to the cube, but able to freely walk around. I’m assuming by the game he has linked, that he wants the player to attempt to use their movement method to not fall off the cube as it’s rotating.
Yes, this right here. The AngularVelocity and LinearVelocity route seems to be working well so far. You mentioned a heartbeat loop a few minutes ago. Not too sure what that fully is, but should I replace the while wait loop with it?
Yes.
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function(deltaTime)
-- do stuff
end)
Although Heartbeat fires after physics step, so I would use RunService.Stepped
instead.
You can also just replace the wait()
with RunService.Stepped:Wait()
inside your while loop.
Thanks for the help! How does this look? Also, I have the Torque and Force on Linear and Angular Velocity set to inf in the properties. Do you think I should leave it at inf, or change it to something like 1,000,000?
local Velocity = script.Parent.AngularVelocity
local Linear = script.Parent.LinearVelocity
local RunService = game:GetService("RunService")
while RunService.Stepped:Wait(5) do
Velocity.AngularVelocity = Vector3.new(
math.random(-30,30)/100,math.random(-30,30)/100,math.random(-30,30)/100)
Linear.LinearVelocity = Vector3.new(0, 0, 0)
end
Using :Wait()
on an RBXScriptSignal (such as RunService.Stepped
) does not work as waiting a certain duration when a number is inserted in the first argument. This is why I suggest using math.noise
. However, your method here works perfectly find for random linear angular rotation, so just simply use this:
local Part = script.Parent
local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
Part.LinearVelocity = Vector3.new(0, 0, 0)
end)
while task.wait(5) do
Part.AngularVelocity = Vector3.new(math.random(-30,30)/100, math.random(-30,30)/100, math.random(-30,30)/100)
end
Thanks again for all the help. However, I’m getting an error that says: LinearVelocity is not a valid member of Workspace “Workspace” - Server.
I have a LinearVelocity in Part that is set to VectorVelocity (0,0,0), so I’m not sure why I’m getting this error. Edit: Just realized it was also an error in the code I posted before, but with that code the cube still spun.
I’m assuming the script should go inside a part instance not the ‘Workspace’ contrainer itself.
local Part = script.Parent
local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
Part.LinearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
end)
while task.wait(5) do
Part.AngularVelocity.AngularVelocity = Vector3.new(math.random(-30,30)/100, math.random(-30,30)/100, math.random(-30,30)/100)
end
This script seems to be working right now. I just set the property I was changing to be more specific for both AngularVelocity and VectorVelocity.
Use the corresponding Assembly provided properties that come shipped with BaseParts. I’ve had bad luck with these, so I’ve had to resort to using Velocity
and RotVelocity
. Despite being deprecated, they somehow work better as the Assembly properties just don’t work at all for me.
Parent this script in the part you want rotating. It’s also recommended to put this as a server script.
local Part = script.Parent
local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
Part.Velocity = Vector3.new(0, 0, 0)
end)
while task.wait(5) do
Part.RotVelocity = Vector3.new(math.random(-30,30)/100, math.random(-30,30)/100, math.random(-30,30)/100)
end
I pasted that script in but it doesn’t seem to be working. I think by using Velocity and RotVelocity, it’s taking the LinearVelocity and AngularVelocity vectors aspect out of it. It could also be that I’m just doing it wrong. With the script I pasted above, the properties were working fine (not sure if these are the same properties that weren’t working for you). I think my next step is transitioning the code into a repeat until loop for 90 seconds or until everyone on the cube falls off.
I’ll do some testing on my own about this. I’ll let you know about a successful result.
local RunService = game:GetService("RunService")
local Part = script.Parent -- Change this to the location of the part(s)
local function UpdatePart(part: BasePart, rotVelocity: Vector3): ()
if (typeof(part) == "Instance") then
if (part:IsA("BasePart")) then
local Atttachment = part:FindFirstChildWhichIsA("Attachment")
if (not Atttachment) then
Atttachment = Instance.new("Attachment", part)
end
local LinearVelocity = part:FindFirstChildWhichIsA("LinearVelocity")
if (LinearVelocity) then
LinearVelocity.VectorVelocity = Vector3.new()
else
LinearVelocity = Instance.new("LinearVelocity", part)
LinearVelocity.Attachment0 = Atttachment
LinearVelocity.MaxForce = math.huge
LinearVelocity.VectorVelocity = Vector3.new()
end
if (typeof(rotVelocity) == "Vector3") then
local AngularVelocity = part:FindFirstChildWhichIsA("AngularVelocity")
if (AngularVelocity) then
AngularVelocity.AngularVelocity = rotVelocity
else
AngularVelocity = Instance.new("AngularVelocity", part)
AngularVelocity.Attachment0 = Atttachment
AngularVelocity.AngularVelocity = rotVelocity
AngularVelocity.MaxTorque = math.huge
end
end
end
for i, v in next, part:GetChildren() do
UpdatePart(v, rotVelocity)
end
elseif (typeof(part) == "table") then
for i, v in next, part do
if (typeof(v) == "Instance" and v:IsA("BasePart")) then
UpdatePart(v)
end
end
end
end
coroutine.wrap(function()
while (true) do
UpdatePart(Part, Vector3.new(math.random(-30, 30)/100, math.random(-30, 30)/100, math.random(-30, 30)/100))
task.wait(5)
end
end)()
There you go. Your method of Linear/AngularVelocity instances in a part seemed the way to go. Apologies for my misunderstanding.
That script supports multiple parts, and not just one. So you could have a folder of parts of which will specifically rotate.
This will also automatically create the instances needed to get this working. So all you have to do is just create parts, the script will do the rest.
Wow, thank you so much! Really appreciate it.
Of course, hope your game turns out nice.
hey is there any way you could make me a script just like this but it works while the cube is anchored?