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?