Gravity Pull Effect

Yes, it is a percentage, but the “1 -” doesn’t make it a percentage.

When I divide the player distance by the max distance it gives me a percentage value depending on how far the player is. 0% if the player is in the center, 100% if the player is on the edge. Though we want the opposite, therefore I do 1 - the original percentage value to get the inverse of that percentage. Now it’s 100% in the center and 0% on the edge.

Using the example above, if the player is 10 studs away then we get:
local force = 4000 * (1 - 10 / 100)
local force = 4000 * (1 - .1)
local force = 4000 * .9
local force = 3600

if the player is 90 studs away then we get:
local force = 4000 * (1 - 90 / 100)
local force = 4000 * (1 - .9)
local force = 4000 * .1
local force = 400

The math.min is to make sure we don’t multiply with negative numbers and the percentage value is between 0 and 1.

Thanks for the explanation! Although I don’t think you would be able to get negative numbers through magnitude checking.

I meant if the distance is a 110 and you divide by 100 your going to get 1.1. Then when you do 1 - 1.1 you get a negative number of -.1 making the force -400.

1 Like

Alright even after trying both solutions I’m still getting the back-and-forth motion. I don’t know what could possibly be wrong. If you are still willing to help, I strongly encourage you to edit the place in the link yourself because I feel I might be doing something wrong.

Here is the link, its open access.

Again, Thank you for your help.

The solution here is very close to how I would solve it, but not quite right to me. The Linear Velocity constant is handy because it calculates a force that keeps a constant velocity, instead of applying a constant force, as constant force is constant acceleration. So My answer would be:

	-- grab the direction.unit and multiply by force
	local force = ((partPosition - Character.PrimaryPart.Position) * Vector3.new(1,0,1)).Unit * 5000 --Vector3.new(1,0,1) is used to cancel out any downward force

	if partPosition - Character.PrimaryPart.Position > 0.1 then--prevents jittering at the center of the circle
		force = Vector3.zero
	end

	-- Apply force
	linear_velocity.VectorVelocity = force

Yes this does mean that it only works properly flat on the ground, but that can be changed. Hope this helps! :grin:

I got an error for the line

if partPosition - Character.PrimaryPart.Position > 0.1 then--prevents jittering at the center of the circle
		force = Vector3.zero
	end

“Attempt to do math on vector three”

I forgot to take the magnitude, whoops!

if (partPosition - Character.PrimaryPart.Position).Magnitude < 0.1 then--prevents jittering at the center of the circle
		force = Vector3.zero
	end