How to make an character levitate

Similar to:

This wont actually do anything in my code since its just gonna use some body position things etc. but what i want is to try maybe make this levitation feature in my flying system if you want to know the code then check this post below!

This also uses body position stuff but i don’t really know how to make it actually levitate maybe? Animations but that would make me more efforts but i would like to know if there is anyway to use BodyPosition with an Existing BodyForce and BodyGyro with the first topic i included fused and work together i would like some examples too!

so is there actually no way to do this other then animations?

1 Like

You can potentially use Humanoid.HipHeight. Just make this value higher and the Character should levitate higher

1 Like

but it levitates them higher not up and down levitation ill just try to fix this if i can

1 Like

Perhaps you can add a script in the character script that changes the character’s hip height using RunService. In the script, you can make a loop that would change the hip hight from a higher value to a lower value to give your levitation effect.

1 Like

Can’t you just use a BodyVelocity?

1 Like

ok but how to add body velocity to character?

1 Like

I just figured this out. I’ve been focusing on how to really make a player levitate for a few days now. When it comes to stopping a character with velocity, you can never really make them stop completely. there are timing problems that make it impossible, and it only gets worse the longer you try.

On the other hand, you can just override vertical speed with your own value using the game.Players.LocalPlayer.Character:MoveTo(…) command. I made a script that overrides velocity when you levitate, and levitation doesn’t stray at all.

It works in the starter character scripts, as a local script. I’m a bit new, so hopefully no mistakes were made, but it has been tested.

Edit 2: There is a better version of this script below this post.

-- overrides Y velocity with levitateVelocityY when levitating.
local RunService = game:GetService("RunService")

local chr = game.Players.LocalPlayer.Character
local hrp = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local posLockY = nil
local levitateVelocityY = 0
local initializationDelay = 0
local doLevitate = false


RunService.PostSimulation:Connect(function(delta)
	initializationDelay += delta
	
	-- this triggers levitation when you walk off a ledge (and immidiately after you jump.)
	doLevitate = hum.FloorMaterial == Enum.Material.Air
	
	if doLevitate and initializationDelay > 2 then
		if posLockY == nil then
			posLockY = hrp.Position.Y
		end
		posLockY += levitateVelocityY
		chr:MoveTo(Vector3.new(hrp.Position.X,posLockY,hrp.Position.Z))
		-- this keeps the real roblox velocity from continuously building up as you levitate.
		-- You can set the y coordinate to a small positive number to disallow landing on the ground.
		hrp.Velocity = Vector3.new(0, 0, 0)
	else
		posLockY = nil
	end
end)

EDIT: levitateVelocityY was initialized at the wrong value.

1 Like

it’s really simple, i dont know why people overcomplicate it.

local BV = Instance.new(“BodyVelocity”)
BV.P = math.huge
BV.Parent = char:FindFirstChild(“HumanoidRootPart”)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
game.Debris:AddItem(BV, 7.5)

1 Like

Do note that BodyVelocity is depreciated, so use of LinearVelocity is encouraged in the docs. Also note that if you intend on being able to stop on a single point, without drifting away at an exponentially increasing speed, you’ll need to use MoveTo, or something similar.

I have already tried zeroing in on the values needed to fully stabilize levitation using velocity-based methods, but due to exponential gain, combined with the instability of fine velocity values, it is impossible and unstable unless you use something like MoveTo, or something similar, which can overwrite the vertical speed.

If you really just want to fall upwards at some speed, or you want steady levitation to be unstable for some reason, then your code will work. otherwise, something with MoveTo would be required.

1 Like

ok but it’s still a way of making a character levitate, while yes i can use linearvelocity i just provided a easier method for the person

1 Like

I very recently realized that horizontal (flat) velocity cannot be retained with my script above because roblox tries to correct the player’s position. (If, in my first script, you replace Vector3.new(0, 0, 0) with Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z), you will see the player drift to the side.)

If you want to override vertical velocity, yet retain horizontal velocity, this new script is will be very useful.

-- overrides Y velocity with levitateVelocity.Y when levitating.
local RunService = game:GetService("RunService")
local Character = game.Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")

local initializationDelay = 0
local doLevitate = true
local positionLock = nil
local levitateVelovity = Vector3.zero
local horizontalAirSpeed = 1 -- 1 is normal air speed, 0 is motionless

local function overrideCharacterY(character: Instance, doLevitate: boolean, positionLock: Vector3, levitateVelocity: Vector3, horizontalAirSpeed: number, delta: number)
	-- returns positionLock, and doLevitate, so that they can be set.
	local hrp = character:WaitForChild("HumanoidRootPart")
	if doLevitate then
		if positionLock == nil then
			positionLock = hrp.Position
		end
		positionLock += (levitateVelocity*delta)+Vector3.new(hrp.Velocity.X*horizontalAirSpeed*delta,0,hrp.Velocity.Z*horizontalAirSpeed*delta)
		character:MoveTo(Vector3.new(positionLock.X,positionLock.Y,positionLock.Z))
		-- this keeps the real roblox velocity from continuously building up as you levitate.
		-- You can set the y coordinate to a small positive number to disallow landing on the ground.
		hrp.Velocity = Vector3.new(0, 0, 0)
	else
		positionLock = nil
	end
	return positionLock;
end

RunService.PostSimulation:Connect(function(delta)
	initializationDelay+=delta
	doLevitate = Humanoid.FloorMaterial == Enum.Material.Air
	if initializationDelay >= 2 then
		positionLock=overrideCharacterY(Character,doLevitate,positionLock,levitateVelovity,horizontalAirSpeed,delta)
	end
end)

Edit: overrideCharacterY no longer writes to doLevitate. It wasn’t needed.