Best way to code a grab?

Hey, and thanks for reading in advance.

I’ll spare you the details on this one - I really don’t have any code to share with you, just in need of ideas. Only two of the many classes in the fighting game I’m working on have access to grabs, and while they’ve been functional, they haven’t been practical or pretty. Cleanly attaching one character to another for a short period of time requires a hefty amount of prepwork and failsafes to make sure nothing goes awry on either the grabbed or the grabber’s end.

That said, what’s the ideal way to code a grab? Here are the things I’ve tried:

  1. Welding the target’s root to the grabber’s arm/root etc
  2. Placing a bodyposition in the target and rapidly positioning it to the front of the grabber
  3. Welding the target’s root to a part rapidly-cframed in front of the grabber
  4. Rapidly cframing the target to the worldposition of an attachment on the grabber
  5. Combinations of the above

Any tips or advice are appreciated!

3 Likes

I have always used a WeldConstrant or Weld combined with setting the .PlatformStand property of the Humanoid being grabbed to true, and it works perfectly.

Are you making sure to set PlatformStand to true so that the opposing player loses control?

2 Likes

Can’t they undo that with backspace?

I don’t think this is so. If you manually set PlatformStand to true it won’t change until you manually revert it as far as I know.

Do you have to set the network owner of the grabbed player’s parts to the grabber?

I have never had to do this in past experiences. Welds seems to do a good job keeping things right by themselves. Just make sure to create the Weld from the Server.

I would also recommend welding from HumanoidRootPart to HumanoidRootPart for the best consistency.

It seems that the behaviour of being able to end the PlatformStand state with backspace no longer exists at least as far as I’ve tested in Studio. I don’t even know when this was changed or if there was ever an announcement, but that’s an interesting thing to note.

The other option apart from PlatformStand is to use the Physics state (must be set with ChangeState) - this is effectively the same as PlatformStand except you need to explicitly use ChangeState to end the Physics state. Changing the state to GettingUp after Physics is common and preferred.

When the physics/PlatformStand state is enabled, this allows the Humanoid to be influenced by other physics mechanisms which is perfect for grabbing. Welding and network ownership are also a treat, minus the problem of dealing with exploiters being able to do as they want with parts they network own.

Energy gave you a pretty solid answer there. Moving the Humanoids with physics probably wouldn’t be fast enough and CFraming might get tedious, clunky, annoying or not in the fashion you want.

7 Likes

Lurking as usual, colbert? :smirk:

Thanks, though!

1 Like

Hello! Sorry for bumping the thread, but there are some issues with welding the HumanoidRootParts together. When welding them together, the Humanoids become synced, and the one who is welded (Part0) cannot die. Is there another solution?

make try making the weld then getting the cframe the grabbed will have upon weld then destroy the weld