Using velocity to pull a player toward a certain point

I’d like to use velocity to pull a player toward a certain part (Since I want to maintain collision, and let them fight against the pull a bit). Preferably, when the player is in range, they’re pulled to that point more and more the closer they are, using their velocity as a means to do so. I have some code written out with some things I’ve tried, but it doesn’t quite give me the results I wanted:

--Object functions
local function Update() --This fires every render step after the player has gotten into range.

	--Adjust speed
	local diff = hrp.Position - goalpart.Position
	if diff.Magnitude ~= 0 then
		hrp.AssemblyLinearVelocity += (-diff/5)
	end
		
	--Get distance, and cancel if necessary
	if diff > 100 then
		Cancel()
	end
end

This works for the most part, but the pull gets stronger the farther away from the part you are, which makes it impossible to leave its pull if you get far enough. I’d like it to get stronger the closer you are, if anything, but mostly, I just want to prevent what it’s doing now.
Also, preferably, I’d like it if the velocity could be calculated in local space instead of global space like it is now, to make things easier for me in the future.
How might I be able to do these things?

Personally I would use align position instead. Then you can do something like this

— in loop

if distance < 100 then
   alignPos.Enabled = true
else
   alignPos.Enabled = false
end

To set this up create one attachment inside the character and one inside the center. Then create an align position. Mess around with the values so it isn’t too strong. Good luck!

1 Like

For me, mostly when using velocity for a “pulling” force. I use the LinearVelocity object.

1 Like

Thanks! Although I probably should’ve mentioned this in the original post, but I’d totally use BodyMovers if I was able, it’s just that with the way things are handled right now (the HRP is anchored, using custom collision), I’m not able to. So I’m just trying to think of a way to code it in manually.

Roblox has a physics service wherein you can register and set collision groups and set it to a part.CollisionGroup property.

1 Like

Thank you, although I know about collision groups, I just have a collision system of my own I’d like to use. The collision is fine, I just need to figure out the math involved in making this function work.