mine checks every frame also to adjust the force and that is how a hoverboard works, it applies force with magnets or something of the sort against the floor. The force increases with more weight so
I’ll try yours if Idiomic’s solution doesn’t work, his seems more interesting though which is why I want to see if it works
@IdiomicLanguage when I get home from school I’ll give a more detailed reply and post how I am applying the equations-sorry for the wait
Heres what I’m doing
local ignore=env.Ink.Black{workspace.Debris}
local cast=env.Spatial.Cast
local v3=Vector3.new
local cf=CFrame.new
local height=5
local maxaccel=1000
local board=script.Part:Clone()
board.Parent=workspace.Debris
local mover=board.VectorForce
local move=board.Move
move.Position=v3(0,0,0)
env.Beat:Connect(function(dt)
local p=board.Position
local hit,h,n=cast(p,-move.WorldAxis*1000,ignore)
local a=math.clamp(-board.Velocity.Y^2/(2*(height-(h-p).Magnitude)),-maxaccel,maxaccel)
mover.Force=v3(board:GetMass()*a,0,0)
end)
I’m running at heartbeat to incorporate the newly applied gravity as part of the velocity
This doesn’t really work though:
https://gyazo.com/c1c6eb65353ddd9bb82300671d4de890.gif
Could you explain what all of these variables are?
I’m envisioning something more like this:
local g = v3(0, -196.2, 0)
local maxAccel = v3(0, 500, 0) - g
local stopping = false
local function getRequiredYAccel(v, h)
return -v * v / (2 * h)
end
env.Beat:Connect(function()
local acceleration
... -- include code for x and z [de/a]cceleration
if curHeight > maxHeight then
if stopping or getRequiredYAccel(board.Velocity.Y, curHeight - maxHeight) > maxAccel.Y then
stopping = true
acceleration = acceleration + maxAccel
end
else
stopping = false
acceleration = -(g + board.Velocity)
end
mover.Force=v3(board:GetMass()*a,0,0)
end
thats the delta h you need to travel
height is desired offset from ground (constant),p is the board position,h is the ground position (raycast)
also your code has a lot of typos, like you’re declaring acceleration within heartbeat but then you’re incrementing it in currHeight>maxHeight branch
also do you mean to write this?
mover.Force=v3(board:GetMass()*acceleration,0,0)
If the board is 15 studs high, the ground is 10 studs below that, then depending on if the function you supplied returns the distance to the ground as positive or negative we get (h - p).magnitude = -5 or -25
assuming that h and p will always have the same x and z coordinates. If the desired height is at 10 studs above ground, then height - (h - p).Magnitude = 15 or 35
, neither of which is the correct distance from the current height to the maximum height above ground. That may be part of the reason why the code didn’t work.
Defining it inside of heartbeat was not a mistake. The acceleration that needs to be applied to the board should be recalculated every heartbeat. I don’t want to keep around the old variable from the last run to store state which could cause bugs down the road if the code was changed improperly.
Yes. I did make a mistake here. a
should have been acceleration
.
Have you attempted to make the hoverboard using this method again?
Your code is too buggy, I’ll just use springs