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.
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.
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.
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)
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.