Set part center to mouse position? / Not make part leap over

So I’m trying to make the slide of this gun move with the mouse position, but whenever you click on a place that is not the center it just kinda leaps over. I don’t want that, the slide shouldn’t just move instantly to a different place so I guess the way to do that would be to set the part center to the mouse.


It shouldn’t just leap over like that when I click it.

1 Like

i think you can make a invisible part and then you teleport the invisible part to the mouse position every time you click it
then you weld the invisible part and the slide together (make sure the slide are still in the same place after you weld them)
when the player stop holding the mouse button you unweld them

for some reason the welded part isnt going with the slide? the slide is unanchored and the part is anchored, im using weldconstraints.

maybe use normal weld because weldconstraints are kinda weird

ok, it works now. but for some reason the exact same thing still happens when i click it. is there another way to do this maybe?

i think after you weld the slide you have to teleport the slide back to it position (or you can change the weld.C1 thing)

could you clarify that please?

basically when you weld part 0 to part 1 then part 1 position will snap to part 0 position
so you have to teleport the slide back to it old position (basically the position before you do the welding stuff)

ok but now i have the same problem as last time where the slide doesnt move, im not using weld constraints

also you have to change a bit of the script too
move the invisible part instead of the slide

i did. and i can confirm the invisible part is moving the slide isnt.

the weld is not active (you have to unweld other stuff that are welded to the slide too)
this is the only solution i can think off to fix the leap thing

nothing else is welded to the slide :confused:

i think it didnt active because the slide are anchored
unachored the slide after you weld it then anchor it back after you unweld the slide
(how come no one have come up with other solution)

Use math.clamp to stop it from going too far, which appears to be when it moves too quickly.

that isnt the problem, read the topic description.

i think the other solution would be like this:
basically it still have invisible part but you dont use the weld
you would need to calculate the distance between the slide and the invisible part
and you can get the slide position by doing

InvisiblePart.Position + Distance

what is the “Distance” supposed to mean?

basically the distance between the slide and the invisible part

Distance = Vector3.New(Slide.Position.X,0,Slide.Position.Z) - Vector3.New(InvisiblePart.Position.X,0,InvisiblePart.Position.Z)

i put 0 in the y position because you dont need to calculate the height distance

attempt to call a nil value error?
{Position = game.Workspace.cam.invp.Position + Vector3.New(game.Workspace.cam.gun.main.Slide.Position.X,0,game.Workspace.cam.gun.main.Slide.Position.Z) - Vector3.New(game.Workspace.cam.invp.Position.X,0,game.Workspace.cam.invp.Position.Z)}