Limiting the viewmodel's rotational sway to a circular limit?

I would like to know how to limit a viewmodel’s weapon sway to a circle similar to Deadline and Insurgency, where if the viewmodel attempts to exit this limit, it will essentially just lock itself at that point in the circle’s circumference even when moving the camera.

I have attempted to try to figure out how to do this, from searching about this topic about limiting the end position of 3D objects to the circumference of a circle while rotating around an origin point. There is nothing about this topic as far as I’ve searched. Some solutions I’ve tried included using the camera CFrame, but I’ve tested that the mouse delta works better for this.

Basically, all in all, I want to know how to limit the end position of a view model while rotating around some sort of origin point using mouse delta. I’d be glad if someone pointed me in the right direction.

Example:

Deadline Weapon Sway Locked to Circular Limit (youtube.com)

1 Like

Very limited answer to this, but id start with math.clamp if i was limiting anything.

It’s a good start, but I want to try to limit it to the circumference of the circle and not let the X and or Y values of the end part CFrame of the viewmodel go past that circumference.

The answer is math.clamp().
You need to clam the rotation of the CFrame