Rotate objects with a swivelled mount around an anchor point via VRC Pickup grips, synced using Smart Object Sync.
Make sure to add Maellon’s Listing since this package depends on Smart Object Sync.
Then head to my VCC Listing and follow the instructions there.
This project uses custom git filters to reduce the amount of noise generated by Udon and UdonSharp. These filters are not required in order to contribute, though without them all UdonSharp asset files will show as modified and those “changes” should not be committed.
This package also contains an extra file about Quaternion math in Unity, in the hopes of providing intuition when working with them.
There’s 3 scripts:
This script is to be put on a vrc pickup.
This script does two things:
<= 0.1No matter which constraint approach is used, the CannonGripRestrictor should be used for all of them when setting up an aim-able cannon.
The constraints are responsible for actually rotating the cannon based on the grips movement. In this document a setup with a cannon and a mount it is mounted in will be described, such that the cannon can be aimed horizontally and vertically where the mount only rotates around one axis. In other words it will behave as though the mount is enabling horizontal rotation while the cannon rotates with the mount but the cannon can also rotate/tilt vertically.
It is possible to use the existing constraints provided by Unity and VRChat. For this setup, have a hierarchy as follows:
Cannon
┣╸Mount (the up (green arrow) direction must be the literal up)
┣╸Cannon (the up (green arrow) direction must be the literal up)
┗╸Grip
Where:
Mount has a rotation constraint with Cannon as the target with locked rotation around the Y axisCannon has an aim constraint with Grip as the targetGrip
CannonGripRestrictor with Cannon as To Snap ToVRCObjectSync or SmartObjectSync on itThis is effectively the exact same as VRC/Unity Constraints, except that if one wanted to have a different constraint setup, well that is possible when using VRC/Unity Constraints, whereas this script is specifically made to perform a rotation and aim constraint. The upside is that this script has no constant performance cost while constraints do.
Requires Smart Object Sync.
Hierarchy:
Cannon
┣╸Constraint (doesn't matter where this object is)
┣╸Mount (the up (green arrow) direction must be the literal up)
┣╸Cannon (the up (green arrow) direction must be the literal up)
┗╸Grip
Where:
Constraint has the CannonAimAndRotationConstraint script on it
Grip as Obj SyncMount as To RotateCannon as To AimGrip
CannonGripRestrictor with Cannon as To Snap ToSmartObjectSync on itThis script is quite notably different in that it has the option to define limits for how much the grip is allowed to be rotated/moved to the left, right, down and up, each of those direction defined as separate angular limits.
Hierarchy:
Cannon
┣╸Constraint (doesn't matter where this object is)
┣╸Mount (all 3 directions, up, forward and right, must be clean)
┃ ┗╸Cannon (the rotation does not matter)
┗╸Grip
Where:
Constraint has the CannonSpecializedConstraint script on it
Grip as Obj SyncMount as MountCannon as CannonGrip
CannonGripRestrictor with Cannon as To Snap ToSmartObjectSync on itcom.jansharp.cannon-grip
Undefined
1.0.2 (Changelog)
2022.3 or later
No dependencies
No legacy packages