Hello, I am trying to create a hoverboard script. What I want to occur is for the board to lift up to its hover height when it’s close to the ground, and float back down to the hover height when it’s above.
My design: A flat part with 4 thrusters attached to the corners. I already figured out the force each thrust needs to maintain to keep the board floating, regardless of the height.
Using my basic understanding of physics, I calculated the mass of the hoverboard with the 4 attachments and multiplied it by the gravity constant for Roblox. This got me:
F = (Mass of turqoise part + Mass of 4 blue parts)(196.2) = 4256.3628
I then divided the force by 4 to get the thrust each thruster needs to maintain which came out to be 1063.012. This force is applied in the Y direction using the BodyThruster’s Force property. I set the Force Property to (0,1063.012,0). Before adding in the code, I got the result shown below where the board is floating statically in the air.
Thrusters are blue, the hover pad is turquoise, the thrusters are all welded to the turqoise board.
https://gyazo.com/4fbd95c3b202d5853f8605106a121188
Now my next step is coding the board so that the thrust is determined based on the height. This is where my physics understanding comes short, unfortunately.
Logically, the thrust needs to be multiplied by a factor such that the thrust must be:
Equal to its self (1063.012) when I’m at the height I want (factor = 1)
Greater than 1063.012 when we are below the height (factor > 1)
Less than 1063.012 when are above the height (factor < 1)
The equation that I came up with was this:
https://gyazo.com/36e30a4af9941ffb208ce3815db26010
So, I set up a while loop that fires a ray straight down the hoverboard (Turquoise). Then I calculate the height (Distance between the board and whatever it touched) and use it to calculate the Thrust as shown below on lines 18 and 19.
rayCastParams.FilterDescendantsInstances = {script.Parent} -- Setting up the ray to ignore the hoverboard
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
local Height
local Thrust
local MAX_VERT_HOVER_DISTANCE = 12.6
--local DAMPENING_CONSTANT = 0.6
while true do
rayOrigin = script.Parent.Position -- Starting point of the raycast
local rayCastResult = workspace:Raycast(rayOrigin,rayCastDirection)
local hitWorldPoint = rayCastResult.Position -- The position of the point the ray hit
Height = math.abs(hitWorldPoint.Y - rayOrigin.Y) -- Height calculated based on just the Y property of the origin and Y propert of the hit point
Thrust = ((1063.012 * (MAX_VERT_HOVER_DISTANCE)) / (Height)) -- Thrust based on my chosen formula
--Setting the thrust
tableOfThrusters[1].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[2].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[3].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[4].BodyThrust.Force = Vector3.new(0,Thrust,0)
wait()
end
The result is shown below in this gif
https://gyazo.com/3f72c7cdbb2c5b7b5f9fd3fc9276769d
After looking at some scuffed hoverboard free models I noticed most of them use something called a dampening constant. Im not too familiar with the term but I assumed it was just a value that limits how fast a value is reached (The value we to reach is 1063.012). I implemented a dampening constant by just multiplying the formula by a random value, in this case I chose 0.6.
The new formula and code are listed below
https://gyazo.com/4049c000365df23bddba5daebf59e47e?token=70bd9c657dc23841e009476852923c05
local tableOfThrusters = workspace.HoverThrusters:GetChildren()
local rayOrigin
local rayCastDirection = Vector3.new(0,-1000,0) -- The distance and Direction I want my ray to travel
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {script.Parent} -- Setting up the ray to ignore the hoverboard
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
local Height
local Thrust
local MAX_VERT_HOVER_DISTANCE = 12.6
local DAMPENING_CONSTANT = 0.6
while true do
rayOrigin = script.Parent.Position -- Starting point of the raycast
local rayCastResult = workspace:Raycast(rayOrigin,rayCastDirection)
local hitWorldPoint = rayCastResult.Position -- The position of the point the ray hit
Height = math.abs(hitWorldPoint.Y - rayOrigin.Y) -- Height calculated based on just the Y property of the origin and Y propert of the hit point
Thrust = ((1063.012 * (MAX_VERT_HOVER_DISTANCE)) / (Height)) * DAMPENING_CONSTANT -- Thrust based on my chosen formula
--Setting the thrust
tableOfThrusters[1].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[2].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[3].BodyThrust.Force = Vector3.new(0,Thrust,0)
tableOfThrusters[4].BodyThrust.Force = Vector3.new(0,Thrust,0)
wait()
end
The result is shown below
https://gyazo.com/f261f160cd4973e0d2f9535dc02f7339
I don’t understand the next step to this, as my physics knowledge is really lacking. I know eventually, I will need to code it so that the weight of the player is factored into the calculation of the thrust, but before I do that, I need to the board to be stable on its own.
The vision I want for the board is that when it dips down below the max height (12.6) I don’t want it to shoot back up past 12.6. It should stably reach the 12.6 height.
Physics lords help me, please.
Also as a side note: Has anyone ready Physics for Game Programmers and found it useful to development on Roblox?