Disabling Gravity On Client

Hello! So, I have this code (I want the player to float for a few seconds and then go down):

Server
local RenderEvent = game:GetService("ReplicatedStorage"):WaitForChild("RenderEvent")
RenderEvent.OnServerEvent:Connect(function(plr, amplitude)
    	local probs = math.floor(math.random(0, 100))
	
	if song.IsPlaying and amplitude <= 2.5 and probs == 1 and activated == false then
		
		activated = true
		
		local char = plr.Character or plr.CharacterAdded:Wait()
		local hum = char:WaitForChild("Humanoid")
		local hrp = char:WaitForChild("HumanoidRootPart")
		local animator = hum:WaitForChild("Animator")
		
		local animation_floating = game:GetService("ReplicatedStorage"):WaitForChild("animations"):WaitForChild("floatings"):WaitForChild("floating_001")
		local load_floating = animator:LoadAnimation(animation_floating)
		
		load_floating:Play()
		
		local tween_info_start = TweenInfo.new(5)
		local tween_properties_start = {Position = Vector3.new(char.PrimaryPart.Position.X, char.PrimaryPart.Position.Y + 20, char.PrimaryPart.Position.Z)}
		local tween_start = TweenService:Create(char.PrimaryPart, tween_info_start, tween_properties_start)
		
		--hrp.Anchored = true
		tween_start:Play()
		tween_start.Completed:Wait()
		--hrp.Anchored = false
		--char:MoveTo(Vector3.new(char.PrimaryPart.Position.X, char.PrimaryPart.Position.Y + 20, char.PrimaryPart.Position.Z))
		task.wait(20)
		activated = false
		if load_floating then
			load_floating:Stop()
		end
		
	end
end)

The problem is that when the player is floating, the player is affected by gravity (constantly fighting with the tween), but disabling the workspace gravity is not an option, since there will be an option in the game on the client side that prevents that you can float. I tried anchoring the humanoid, but I want the player to be able to move while floating.

Notes:

  • The event is emitted on each frame (RunService.RenderStepped)
2 Likes

You can simulate gravityless using a VectorForce on the HumanoidRootPart with an upward force equivalent to HumanoidRootPart.AssemblyMass * workspace.Gravity

3 Likes

This is absolutely possible, and it is more simple than you may think!

From a local script, you can change the properties of workspace to fit your needs:

game.Workspace.Gravity = 20 --Default is 50

You could also pair this with a Tween to make the gravity fluctuate.
Since this is done locally (on the Client), only your movement will replicate to other players (you will appear low gravity)
The gravity of Workspace will remain the same for all other players.

3 Likes

This is great for simulating projectiles, and a bunch of other cool stuff.
All non-massless BaseParts have a specific Mass which can be used to simulate physics of said objects when coupled with the other in-game Roblox Physics properties.