Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Asking for some direction/pointers on a gravity script?

What I am trying to do: create a localscript that changes the gravity of the game once they reach a certain altitude to mimic the effects of free floating in outer space What I have done so far: the script essentially works, once the player reaches y>=10000, the gravity of the game is set to 0 (as 0/9.81*196.2 = 0) What is the problem / question?: as a player uses an object that moves at a high velocity to propel itself to high altitudes (a rocket), the objects inside that container also are moving at a high velocity, so when the player attempts to eject from the rocket at any altitude of y=10000 or higher, there is no gravity to slow them down, thus they stay floating upwards at a high velocity with nothing to slow them down unless they make contact with an object that would slow them down. My question is, would there be a way to factor in a slowing down effect on the velocity of an object/player once the player reaches a target point or altitude, so that they would be able to float freely in a non-gravity environment so that they are not infinitely propelled upwards?

here is what I have so far, any help is greatly appreciated :^)))

local Player = game.Players.LocalPlayer
local Character = (Player.Character or Player.CharacterAdded:Wait())
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart') 
while wait() do
	if HumanoidRootPart.Position.Y <= 10000 then
--this is set to mimic the gravity on mars, where the game takes place
		local marsGravityRatio = 3.71 / 9.81
		local defaultGravity = 196.2
		local marsGravity = defaultGravity * marsGravityRatio
		workspace.Gravity = marsGravity or defaultGravity
	else
--this is where the gravity changes, once the player escapes mars via rocket, and reaching y>=10000
		local marsGravityRatio = 0 / 9.81
		local defaultGravity = 196.2
		local marsGravity = defaultGravity * marsGravityRatio
		workspace.Gravity = marsGravity or defaultGravity
	end
end

1 answer

✓ Accepted answer

Well, this is actually a pretty easy fix in my opinion.

All you have to do after ejecting the player, change their Y velocity to 0 or act with a counteracting force so that they don't move up and destroy the force after they land.

This discussion is preserved as it was. New answers, comments, and votes are closed.