Anti-Gravity Block!

How to make an Anti-Gravity Block like one you would find in space!

by InsertYourself

Author Avatar

Introduction

Hello learner! In this tutorial, I will be teaching you how to make an Anti-Gravity Block! What is an Anti-Gravity Block you may ask? Well, it's just as the name implies. A block that experiences no gravity!

So what does this look like? Well, if you've ever seen an astronaut before doing a space walk, you will see them floating around with a rope attached. This is because they are so far from the earth that they do not experience the gravitational pull of the earth. Without the rope they would be hurling into space forever!

So this is our goal. To create a block that experiences no gravity!

Background

Let's start with 2 questions. For every row of objects, answer the following: Which object is heavier?

img|80x70

1 The object to the RIGHT because the size is bigger. Imagine comparing the weights of a single pebble vs. a boulder. Although they are both rocks, the boulder has a larger size than the pebble. We call the size "Volume."

2 The object to the LEFT because of the material. You can imagine a bowling ball vs. a soccer ball. The bowling ball is made of a harder material and the soccer ball is made out of a softer material. We call this "Density."

In fact, these two properties are all we need to determine how much "mass" an object has, or in layman terms, how much "stuff" an object has. This is calculated by mass = volume * density

Let's talk about why objects fall

As we said before, astronauts are so far from the earth that they do not experience the gravitation pull of the earth. However, for us on the surface on the earth, we are close enough to experience its gravitational pull. In fact, the earth is pulling down on us with a force of mg (mass times gravity(9.8 m/s^2)).

And so to experience zero gravity, our net force (sum of all forces) must equal 0, like an astronaut!

Let's draw a picture

img|80x70

Fg is the "Force due to Gravity" and is equal to mg. In fact, this is why all objects on earth fall. Any object on any planet experience their planet's gravitational force and is always equal to mg.

So to create an Anti-Gravity Block, we want the net force to equal 0, like an astronaut! With some algebra, we can solve what force must be applied to obtain a net force of 0

Fg + F = Fnet Fg + F = 0 F = - Fg

So our Force needs to equal the negative force of Fg. In fact, we can simplify this even more!

F = - Fg F = - mg

Now that we solved for the force we need, we can start scripting! Finally, huh?

Let's get to Scripting!

We insert a script into our part and declare a variable that references that part

local part = script.Parent

Calculate the downwards force due to gravity (it's negative because gravity is always downwards (our negative direction))

local downForce = - part:GetMass() * workspace.Gravity

Calculate the force we want to apply, which we found out is F = - Fg. Fg is our downForce, so we can reference that rather than re-calculating it.

local force = -downForce

Instance a BodyForce object. This object applies a force to the part it's parented to.

local bodyForce = Instance.new("BodyForce")

BodyForce has only one property. Force. This is the force exerted on the object. We know that the force of gravity is only applied in the Y direction. So we want to apply our force on the same axis.

bodyForce.Force = Vector3.new(0,force,0)

Lastly, we parent our BodyForce to our part

bodyForce.Parent = part

Our Final Script

local part = script.Parent
local downForce = - part:GetMass() * workspace.Gravity
local force = -downForce

local bodyForce = Instance.new("BodyForce")
bodyForce.Force = Vector3.new(0,force,0)
bodyForce.Parent = part

So normally, an unanchored block would fall straight down. Let's see what our block does now O_o

img|80x70

And when we push it...

img|80x45

img|80x45

img|80x45

As you can see, the block is going farther and farther. In fact, it will go-on forever and maintain its velocity! (There is no translational air resistance in Roblox, only rotational resistance. So the block will eventually stop spinning)

Conclusion

Although there was not a lot of scripting (merely 6 lines) I hope you have learned a lot about physics and that I have made this tutorial a fun read to explore sommore with BodyForces! Explore more tutorials in Lua Learning and don't forget to ask questions in the discord server if you have any questions! Toodles!

Thank you for reading, InsertYourself

View in-game to comment, award, and more!