How to apply magnetism to part

Hello there.

So what I need to do is make a part appear on mouse.hit.p. Well, thats done, a part appears on mouse.hit.p.

Now what I need is to be able to make the exact part…

  • Calculate if there’s a player nearby
  • If there’s a player nearby based on how long the magnitude is to the player and the part, go to that player.
    If theres two players nearby, go to the closest one to the mouse.hit.p.

How could I get the position of the nearby player, I heard something about region3 but I don’t know if that is of use.

Some visual that will help.

V Put the ball in the position of the mouse (DONE, I already did this somehow) V
vIDEO1

V If ball is near player, go to player V
vIDEO2

V If ball is near two or more players, go to closest player V
vIDEO3

I know about just getting the position of all players and raycasting to them, but that consumes a lot of process and I don’t want to do that, it has to be in a zone near the place where this mouse.hit.p spot went into, it doesnt have to calculate everything and everyone.

I haven’t personally tried a “magnetism” effect before, however I would think you would wanna use Magnitude instead of raycasting.

Magnitude (roblox.com)

if (ball.position - mouse position).Magnitude < 10 then
– tweening stuff here
end

1 Like