How can I recreate this part grabbing mechanic?

Hi, I’m trying to find a way to recreate this part grabbing system that a game has. I’m not necessarily focused on the green beam, but more so on the part’s levitation and using the scroll wheel to have it come closer or further to an extent. I assume something like raycasting is used, but I’m really not sure on anything else. Any ideas? Thank you.

1 Like

yea i think it welds to the raycast or vice versa

Hmm how about you first cast a ray and see if it hits anything, then if it does you create an invisible part, position it to wherever the ray hit something, add an attachment inside of it and you also anchor it and make it follow your mouse at the initial distance. Then you simply add a AlignPosition (and AlignOrientation maybe) constraint inside the target part and make it align to our invisible part. And scrolling will simply change the distance of that invisible part from your character/camera. That could be done with linear interpolation.

2 Likes

bump, could use some more info

How far have you gotten on your own?

Start by making a client script that can detect when a relevant Model is clicked. Then setup a RemoteEvent to comm with a server script, and fire that from the client script when the player wants to pick something up. In the server script, change the network ownership of the model to the player, and add the AlignPosition and AlignOrientation objects. Keep track of which thing each player is holding somehow, because you’ll need it to ensure cheaters don’t do weird things like picking up multiple things or causing other players to drop things or w/e. Send an event back to the player telling them if the grab was successful or if it failed (like if they tried something invalid, which might happen if cheaters fire RemoteEvents). On the client, if grabbing succeeded, set up effects like a Beam and set up changing the AlignPosition and AlignOrientation every frame, as well as sending events to the server to drop the thing, which should “reset” things on the server like “forgetting” that the player is holding the thing, taking network ownership back, etc.

2 Likes

I get all of that, but I don’t get how the part stays floating and goes wherever the player faces.

I don’t really know how it works but it probably sends a raycast from your mouse onto the part and drags it along with your mouse. (probably using Linear Velocity)

last bump before i hopelessly give up :100:

You’ll need to compute a point in space that’s right in front of the player. The player’s position could be the character’s head’s position or the camera’s position if your game is always just 1st person. Add to that position the direction that the camera is looking, which is camera.CFrame.LookVector * DISTANCE, where distance is however many studs in front of the player you want the object to be held.

Repeat that every frame, and you should get a decent effect that’s pretty close to what’s in the video you posted.