How to make the player slowly float into the air

I feel like my scripting has gotten way better in a short time span, then these issues arise to humble me.

Context: I’m remaking the old classic swords in roblox for a game, a feature I want to include is the lunge making you rise upwards at a steady pace, I don’t want you to shoot up out of no where.

Issue: I can’t seem to figure out LinearVelocities or VectorForces. I also tried the HumanoidRootPart’s AssemblyLinearVelocity. None of them gave me the result I wanted. I assume it’s because the mass of my character was too high but it seemed that too low of a force and my character was glued to the ground, whereas too high of a force and my character would shoot up too fast and too high.
I tried setting all the BaseParts in my character to massless, but I got the same issue just at a lower force.

My goal is something like the levitation effect from Minecraft, a slow glide up. Thank you in advance if anyone knows the solution, I’m pulling out my hair over something that’s probably obvious.

3 Likes

A LinearVelocity should achieve what you are trying to accomplish. I would recommend playing around with the MaxForce and VectorVelocity. There should be a nice sweet spot of these values. You may not want the MaxForce value to be too high, or the velocity might change very quickly and look awkward.

3 Likes

Man I knew it was gonna be obvious, I just didn’t set the MaxForce high enough because I had figured the default 1000 was fine… thanks for the solution, it works great!

1 Like

You should also take a look into AssemblyMass, since some characters are heavier then others and might go up too far and just not go up at all. What I like to do is simply multiply the velocity with the AssemblyMass, however I am using VectorForces so I’m not sure how it works with other Body Movers.

2 Likes

I tried that and a couple of different solutions like multiplying the total character mass by gravity and then adding as much as you want to go up. And like I said I tried setting every BasePart in the character to massless, it still wouldn’t work.
I tried with LinearVelocity, I just had to turn the MaxForce up to get the player off the ground like @ElusiveEpix said to do. I don’t know much about roblox’s physics system but I was surprised the character being massless still didn’t work.

Also, a quick extra question, does anyone know how to let the character move in whatever direction they’d like to while they’re floating in the air? The best I was able to get was they travel in the direction they were initially going when the LinearVelocity was enabled.
Code on what I did to achieve that:

LinearVelocity.VectorVelocity = Vector3.new(HRP.AssemblyLinearVelocity.X,10,HRP.AssemblyLinearVelocity.Z)
LinearVelocity.Enabled = true

You shouldn’t use the X and Z components of the VectorVelocity if all you are doing is moving the object up. You could just set the X and Z components of the MaxForce to 0, and it wouldn’t have any effect on horizontal movement.

1 Like

I’m not using the X or Z of the VectorVelocity, but also I don’t think I have access to the X and Z components of the Max Force, is it a beta feature or am I using the wrong type of force/velocity? I’m using a LinearVelocity?

My bad, I mixed up the old deprecated BodyVelocity with the new LinearVelocity, as the former has MaxForce as a vector and not a scalar.
You will want to change the VelocityConstraintMode to “Line”, then you could set the LineDirection to be up (Vector3.yAxis), then modify the LineVelocity and MaxForce to what you need.

2 Likes

Yesss!! It works perfectly! I didn’t even know that’s what linear VelocityConstraintMode did, thank you so much. I’ll set this as the solution instead since this is the full correct answer.

Hi,I am working with the same problem.Can you show me how you fix it ?pls.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local humanoidRootPart = character:WaitForChild(“HumanoidRootPart”)

local linearVelocity = Instance.new(“LinearVelocity”)
linearVelocity.Parent = humanoidRootPart
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
linearVelocity.ForceLimitsEnabled = false
linearVelocity.LineDirection =Vector3.yAxis
linearVelocity.LineVelocity = 10
linearVelocity.MaxForce = 1000

linearVelocity.Enabled = true
This is my testing code.