I’m trying to make the red cube bounce around the box with black borders kinda like the DVD logo. It works if the part is flat, but because the part is at an angle, gravity instead messes with the cube and pushes it to the bottom.
I tried using a vector force, but I couldn’t get it to work, probably because I don’t understand them real well.
Code
local part = script.Parent
local random = Random.new()
local speed = random:NextNumber(24, 36)
part.CFrame = part.Parent.PrimaryPart.CFrame * CFrame.new(random:NextInteger(-14, 14), 4, random:NextInteger(-44, 44))
wait(1)
-- Ensure that the speed of this part is actually equal to speed
local speed2 = speed * speed -- Speed squared
local xvelocity = random:NextNumber(100, speed2 - 25)
local zvelocity = speed2 - xvelocity
part.AssemblyLinearVelocity = Vector3.new(math.sqrt(xvelocity), 0, math.sqrt(zvelocity))
part.Touched:Connect(function(border)
if border.Name == "Z-Axis" then
part.AssemblyLinearVelocity = part.AssemblyLinearVelocity * Vector3.new(-1, 1, 1)
elseif border.name == "X-Axis" then
part.AssemblyLinearVelocity = part.AssemblyLinearVelocity * Vector3.new(1, 1, -1)
end
end)
local part = script.Parent
local random = Random.new()
local speed = random:NextNumber(24, 36)
part.CFrame = part.Parent.PrimaryPart.CFrame * CFrame.new(random:NextInteger(-14, 14), 4, random:NextInteger(-44, 44))
wait(1)
-- Ensure that the speed of this part is actually equal to speed
local speed2 = speed * speed -- Speed squared
local xvelocity = random:NextNumber(100, speed2 - 25)
local zvelocity = speed2 - xvelocity
part.AssemblyLinearVelocity = Vector3.new(math.sqrt(xvelocity), 0, math.sqrt(zvelocity))
part.Touched:Connect(function(border)
if border.Name == "Z-Axis" then
part.AssemblyLinearVelocity = part.AssemblyLinearVelocity * Vector3.new(-1, 1, 1)
elseif border.name == "X-Axis" then
part.AssemblyLinearVelocity = part.AssemblyLinearVelocity * Vector3.new(1, 1, -1)
end
end)
The to my knowledge easiest method is to insert a BodyForce into the part you want to be weightless. VectorForces are preferred but I too don’t appreciate the additional bloat of one more attachment.
If gravity and the part’s size (mass) is constant, do this one-time for each part you want weightless:
local bodyForce = Instance.new("BodyForce")
bodyForce.Force = Vector3.new(0, part:GetMass()*workspace.Gravity, 0)
bodyForce.Parent = part
If gravity or the part changes you can just repeat the second line within a RunService.Stepped event listener.
You can try making the borders taller, and for viewing purposes make them invisible and re-add your current lines with a different name, cancollide cantouch etc disabled
You’ll need to cancel out the horizonal component of the normal force.
If you do that, the part will “fall” onto the board, but the gravity/normal-force won’t move it sideways. Completely canceling the gravity force will make the block float, but it needs to stay on the board, so that’s not a good solution.
Edit:
Steps:
Calc horizontal component
Create a BodyForce and set the force to the opposite of the horizontal component
Like why do I have to abuse Claude until it spits out some esoteric knowledge so I can get a simple animation working? What features have I or the Roblox dev community written off due to not knowing these secrets?
I genuinely despise using AI. I cannot stand it. The premise is that you speak to it similar to a human; you ask it something and it produces an answer. In practice it does not work this way and completely ignores your input, requiring clever prompt engineering, taunting you as if it is human. Modern web search is bad enough let alone AI. Computers should have stayed having simple algorithms and not “progressed” this much. But unfortunately I always need to find some esoteric setting in the Roblox code so I have to keep using it, which is likely a great failure on my part.