Hello! Welcome to my tutorial.
We are going to learn how to make any object unaffected by the gravity,
using simple physics and BodyMovers. Let’s begin!
First of all, let’s see how it looks with a gravitational impact on it:
https://streamable.com/1d9jtk
When the part is in the air, it falls down.
https://streamable.com/342ub2
We can push it, and when it has no surface to stand on, it falls down.
Why? By laws of physics, every object has a mass. Every object has a gravitational impact on another. For example, when you pick a pencil, the mass of your body is greater than the mass of the pencil, so the pencil is being pushed towards the center of you. Yet, your mass is not great enough to have much impact that we can see with our own eyes. The weight of the object is responsible for this pushing force. So now that we know why all this happens, how do we even calculate weight? Simple.
Mass * Gravity = Weight
is the formula to calculate weight, really simple, and easy to remember.
So, after we know all of that, we can start by getting the necessary variables to calculate the weight.
local object = script.Parent;
local mass = object:GetMass();
local gravity = workspace.Gravity;
So, now we have all our variables. So, we’ll have to create a BodyForce inside the object.
local object = script.Parent;
local mass = object:GetMass();
local gravity = workspace.Gravity;
local bodyForce = Instance.new("BodyForce", object) -- Creating a BodyForce.
bodyForce.Force = Vector3.new(0, 0, 0) -- Setting the force to have no impact at the moment I create it.
Now, we’ll only have to give an equal force pushing the object to the opposite direction that the gravity is pushing it. In reality, weight pushes an object towards it’s center. But in Roblox, it pushes it downwards (correct me if I am wrong, did not make a research about it). So, we’ll have to pick the right axis that’s force is opposing the direction that the gravity pushes. So, we’ll need the Y axis (+).
local object = script.Parent;
local bodyForce = Instance.new("BodyForce", object) -- Creating a BodyForce.
bodyForce.Force = Vector3.new(0, 0, 0) -- Setting the force to have no impact at the moment I create it.
function set_Powers(mass, gravity)
bodyForce.Force = Vector3.new(0, mass * gravity, 0)
end;
while wait() do
local mass = object:GetMass();
local gravity = workspace.Gravity;
set_Powers(mass, gravity)
end
So, we are done. Let’s now test it!
Floating
Not falling downwards (proved in video that the object is unanchored)
Thank you for viewing this tutorial! If you find any mistakes [grammar mistakes i.e information mistakes], comment it, so I’ll correct them.
- Great!
- Good.
- Okay.
- Could’ve been better.
0 voters