How to stop player from dropping out mid air without anchoring their root part?

  1. What do you want to achieve?
    I’m trying to make a flying script using BodyGyros and BodyVelocity, something like this (from Dragon Ball Z Final Stand):

  2. What is the issue?
    I want the player to face the mouse with BodyGyro but since Anchoring their HumanoidRootPart causes BodyGyro to be ineffective, I don’t know how I would lock the player in mid-air

  3. What solutions have you tried so far?
    Tried using the Locked, but the player is still dropping to the ground
    I also tried using BodyPosition, but it isn’t consistent when the player stops flying forward

script.RemoteEvent.OnServerEvent:Connect(function(player,input,mouse,speed)
	local character = player.Character
	local HumaoidRP = character.HumanoidRootPart
	
	
	
	
	
	
	
	
	
	
	if input == "Start Flying" then
		print("Start Flying")
		player.isflying.Value = true
		character.HumanoidRootPart.Locked = true
	end
	if input == "Stop Flying" then
		print("Stop Flying")
		player.isflying.Value = false
		character.HumanoidRootPart.Locked = false
		if HumaoidRP:FindFirstChildOfClass("BodyVelocity") then
			HumaoidRP:FindFirstChildOfClass("BodyVelocity"):Destroy()
		end
		if HumaoidRP:FindFirstChildOfClass("BodyGyro") then
			HumaoidRP:FindFirstChildOfClass("BodyGyro"):Destroy()
		end
	end



	
	
	
	
	
	
	if input == "Forward" then
		if HumaoidRP:FindFirstChildOfClass("BodyVelocity") then
			HumaoidRP:FindFirstChildOfClass("BodyVelocity"):Destroy()
		end
		HumaoidRP.Locked = false
		local Forward = Instance.new("BodyVelocity",HumaoidRP)
		Forward.Name = "ForwardMovement"
		Forward.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		Forward.Velocity = mouse.lookVector*speed
		wait()
	end

	if input == "Forward Ended" then
		print("Forward Ended")
		if HumaoidRP:FindFirstChild("ForwardMovement") then
			HumaoidRP.ForwardMovement:Destroy()
			HumaoidRP.Locked = true
		end	
	end








	if input == "Backward" then
		HumaoidRP.Locked = false
		if HumaoidRP:FindFirstChildOfClass("BodyVelocity") then
			HumaoidRP:FindFirstChildOfClass("BodyVelocity"):Destroy()
		end
		if HumaoidRP:FindFirstChildOfClass("BodyGyro") then
			HumaoidRP:FindFirstChildOfClass("BodyGyro"):Destroy()
		end
		local Back = Instance.new("BodyVelocity",HumaoidRP)
		Back.Name = "BackMovement"
		Back.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		
		Back.Velocity = mouse.lookVector*-40
		wait()
	end

	if input == "Backward Ended" then
		print("BackwardEnded")
		if HumaoidRP:FindFirstChild("BackMovement") then
			HumaoidRP.BackMovement:Destroy()
			HumaoidRP.Locked = true
		end
	end
end)

1 Like

Locked just means whether or not you can select it in Studio.

Have you tried putting a BodyForce into the Humanoid and setting it to upwards force to counteract gravity?

How would I get the perfect amount of force that would keep the player in place?

There’s an anti-gravity calculation in the script in the BodyForce post.

BodyForce is a legacy body mover, soon to be deprecated and deferred.
To the OP, use a velocity constraint.

How do I use this on the player

Countering a players gravity with a force does stop a player from accelerating downwards, but it doesn’t lock a player to a Y position, it just makes them weightless. If some exterior force gave a player Y velocity while weightless, they’d keep a constant velocity floating in that direction forever.

You can use a BodyPosition, which I would say is the easiest solution to keep the player locked on a Y position, change the MaxForce property so it only effects the Y axis, e.g. (0,10000,0) that was the player can still move on the X & Z axes.

6 Likes

Locked means if you can directly select it, it does not affect the game or physics.

You Should use BodyVelocity and BodyForce because body velocity can make the player ethier side to side midair or in any direction and body force helps for no big problem same for body gyro