BallSocketConstraint lagging behind target

I’m trying to create a weapon charm system for my gun engine. My first thought was to use a BallSocketConstraint on the hook, and a second one on the carabiner. Here’s a picture of the breakdown:

The ball model then gets welded to a part on the gun model.

For the most part, this works perfectly in-game:

However, when I move my character, this happens:
2020-09-06_16-59-26
(The carabiner socket lags behind the sphere model that’s welded to the gun.

Additionally, when I first take out the gun, I can see the ballsocketconstraint slowly moving to the desired position:
2020-09-06_18-02-46

This is most likely why I am seeing the results from the second gif, the socket joint doesn’t immediately move to its desired position.

Does any one have any tips on how to fix this issue? Are BallSocketConstraints not the best way to go about attaching two components together?

1 Like

This sounds like a better question for #help-and-feedback:building-support since it’s related to physics.

But, it can depend on maybe how you’re changing the position of the gun:

  • If it’s a normal animation, then you’re probably doing it right to begin with. Double check that Attachment0 and Attachment1 are correct, and perhaps switch their values (IIRC Attachment0 is supposed to be in the direction of your “root”, though I’m not entirely an expert on it).
  • If you’re updating using RunService.Heartbeat (which happens after physics, not before like Stepped), then you could be moving your gun immediately before it gets rendered on the next frame, and physics doesn’t catch up until after it’s rendered. This would cause the carabiner to lag behind by a frame.
1 Like

Thanks, @Ozzypig
Previously I was positioning my gun every frame via:
game:GetService("RunService"):BindToRenderStep("GunRendering1", Enum.RenderPriority.Camera.Value-1024, onRender)

I switched it to being done on the Stepped event. Now it’s perfect without any side-effects.

1 Like

Excellent! Glad I could help. For future reference (and for the reference of anyone reading), see the Task Scheduler article. It outlines what Roblox does every frame.

(I also was the one who wrote it, and I’m quite proud of it)

1 Like

Unfortunately, as it turns out, this breaks some functionality of my gun system. The gun needs to be positioned to the camera before the camera is rendered. As it turns out, on mobile devices the physics tasks are running slightly out of sync from the rendering tasks, causing the gun to become a little laggy, similar to the issue shown in the gif in the OP (except with the whole gun).

Guess I’ll need to come up with my own solution for this.

[EDIT]
What I’m experimenting with now, is adding an additional layer, where I traverse through the ballsocket-charm like a tree, and (via render step) manually set the parts CFrames to the sockets they should be attached to (While keeping their original rotation in tact, to keep the physics simulation there). So far it’s working well, but the physics obviously aren’t as nice.

Unfortunately this is to be expected given the order of things happening each frame :frowning:

Hopefully you can find a solution for mobile users. It sounds like you’re on the right track with manually repositioning the charm parts yourself.