Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make a black hole effect?

I have seen this question all over the place, and I've seen answers, but that doesn't work for me, I need a code that draws players into a part like a black hole would, I've tried


script.Parent.BodyForce.Force = Vector3.new(0, game.Workspace.Gravity, 0) * script.Parent:GetMass()

Which was on the ROBLOX Developer wiki, but that doesn't work. I've also seen people say "Use the Black Hole Bomb script" but that makes no sense to me (Honestly I'm really new to Roblox Lua) so an explanation, even if brief, would be appreciated,

Thanks.

5 comments

0

The script you posted only makes an object have no gravity. I'd suggest using BodyPosition.

0

Hold on I got something for this

0

Make the floor have velocity, its what i did.

0

search up "suck" on roblox toolbar, you will find a trash script of a blackhole suck thing, ignore the other dirty models .

0

You could also check out the black hole bomb gear

1 answer

If I were making a black hole this is what I do. The obvious solution is BodyPosition - but that won't create much of a black hole effect.

You can use some basic vector math to create a much more black-holeish effect with a BodyVelocity (or any number of other BodyMovers).

Solve for the directional vector between any two parts, take its unit, multiply by some amplification, and add it to the simulated gravity defection.

local ob_black_hole, ob_self = workspace.blackhole, workspace.inhole -- where ob_black_hole is the black hole, and ob_self is the part flying toward the black hole indefinitely

local force_amp = 1500 -- the vector amplification for our directional vector

game:GetService("RunService").Heartbeat:Connect(function()
	ob_self.BodyVelocity.Velocity = Vector3.new(0, workspace.Gravity * ob_self:GetMass(), 0) + (ob_black_hole.Position - ob_self.Position).unit * force_amp
end)

If you want a much more linear effect though, BodyPosition is definitely what I would go for.

8 comments

0

Does "workspace" equate to "game.Workspace"?

0

workspace = game.Workspace. It's a shortcut.

0

Also, this code is just to show you how it would work; and would need to be modified to fit your actual use-case.

0

wait so what would "inhole" be? My "Black hole (so far)" is just one part, if that relates to it at all.

0

In this example, black_hole is a part to act as the hole, and ob_self is a part to move relative to the hole. You would need to adjust the variable definitions accordingly.

0

If i wanted to draw nearby players in would I make the var "ob_self" contain "game.Players.LocalPlayer"?

0

This example is more to show you these two formulas for creating the black hole effect so you can use it how you need to. If you were to take the example code as is, then both variables need to represent a single part.

0

Yes, but how would i make it affect players?

This discussion is preserved as it was. New answers, comments, and votes are closed.