How to make player float in air but still allow movement?

I made a script that allow player to dash for a short period of time, and i want to make player able to float mid-air if they dash airborne. So when they dash at the air, they neither fall nor gain allitude from jumping, like being anchored but they still allowed to move horizontally. I’ve tried to use LinearVelocity but that just make my char freeze in place.

What should i use to achieve this?

2 Likes

You could anchor the HumanoidRootPart and use context action service to bind the movement inputs to functions which control it’s movement, then unbind and unanchor when finished.

1 Like

Isn’t this the most complicated way and not the best way to do it, like, anchoring rootPart disable player animation and i don’t want that.

Isn’t there a BodyVelocity or something to do this?

Im sorry for bumping, but this question hasn’t found a solution.

The problem with using LinearVelocity is it will actually set your velocity rather than adding on to it.

Try applying a vector force on the humanoid root part that points upwards. A vector force will simply be added to other forces acting on the body, allowing you to still move on the x and z axes.

The force due to gravity is mass * acceleration due to gravity.

In code:

local force = Instance.new("VectorForce", humanoidRootPart)
force.Force = Vector3.new(0, humanoidRootPart.AssemblyMass * workspace.Gravity, 0)

You’ll also need to create an attachment in the humanoid root part to attach the vector force to.

1 Like

Use body position, you can float and still move around mid air. I’d bind some inputs like ctrl and space to descend and ascend respectively by changing the Y position of the body position.

Tried your method, it still does not stop the player from falling nor rising, althought the Y movement does decrease

Should i add the Y force with Humanoid.MoveDirection.Y ?

BodyPosition is deprecated, so i used the latest one, which is AnglePosition. It freeze player in place, i tried to add it with player move direction and the result is the same

That probably happened because other body parts (e.g. legs, arms, etc.) and items your avatar is wearing (e.g. hats, wings, etc.) also have mass. Try using the entire mass of the avatar, rather than just using humanoidRootPart.AssemblyMass:

local function getCharacterMass(char)
   local totalMass = 0
   for _, v in pairs(char:GetChildren()) do
      if v:IsA("BasePart") then totalMass += v.AssemblyMass end
   end
   return totalMass
end

local force = Instance.new("VectorForce", humanoidRootPart)
force.Force = Vector3.new(0, getCharacterMass(char) * workspace.Gravity, 0)

1 Like

Since im asking this for implementing a dash mechanic, i’ve tinkered with LinearVelocity and i’ve managed to get the result i wanted.

Still, it ended up not like what i asked, since LinearVelocity unlike what i asked doesnt allow XZ movement but atleast it lock player Y in place since thats what im looking for.

But for anyone in the future searching for the same problem. Refer to these two guys solution. While i tried and it doesnt perfectly lock the Y movement, it still does the job well done, just tinker with the Y number until you found a satisfying goal :

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.