c# – Unity Runtime Surface Snapping (Like Shift+Cntrl in Editor)

I am trying to allow the user of my VR game to move objects around using a pointer, then when holding down a button, snap to a grid and align to the highest surface, essentially replicating the Editor behavior or holding down shift+control and moving around a transform gizmo. (Try it, it’s fun!)

I have the grid part down, but can’t wrap my head around how to do the surface snapping.
Here is the code I have so far. I would appreciate any and all help!

// offsetPos is where the VR pointer is.
Vector3 offsetPos = pointer.objectControlPoint.transform.position + cursorOffset;
Vector3 newPos;
if (isSnapping) // Snap to ground code.
// I read previously to do this up then down thing, but It's not working as expected
    RaycastHit groundHit = new RaycastHit();
    if (Physics.Raycast(selectedObject.transform.position, Vector3.down, out groundHit))
         RaycastHit objectHit = new RaycastHit();
         if (Physics.Raycast(groundHit.point, Vector3.up, out objectHit))
                Vector3 snapDiff = groundHit.point - objectHit.point;
                snapYPos = snapDiff.y + (selectedObject.collider.bounds.extents.y);
      // worldGrid is a monoBehavior on another object, and gridCellSize is just a float
      float gridPosX = Mathf.Floor(offsetPos.x / worldGrid.gridCellSize) * worldGrid.gridCellSize;
      float gridPosZ = Mathf.Floor(offsetPos.z / worldGrid.gridCellSize) * worldGrid.gridCellSize;
      newPos = new Vector3(gridPosX, snapYPos, gridPosZ); // Sets the target position to the nearest grid cell, with a Y of the snap position.
else // If not in snap mode, set target position to just the VR cursor.
       newPos = new Vector3(offsetPos.x, offsetPos.y, offsetPos.z);
// I know lerp might not be the most efficient, but I like the smooth effect, and it looks good when snapping to the grid...
selectedObject.transform.position = Vector3.Lerp(selectedObject.transform.position, newPos, movementLerpSpeed * Time.deltaTime);

The objects I need to be snapping all are different sizes and have their origins in different places, but all do have appropriate box colliders.

Thanks so much!

Replacing Command words with sounds, (Like snapping your fingers)

Is it possible, when creating a magic item to replace a command word, for say a wand, or a flaming longsword, to react to a fingersnap or similar sound instead of an actual spoken word?

dnd 5th – Is this homebrew snapping turtle balanced as an animal companion for the UA Revised Ranger (Beast Conclave)?

The ranger player in my group asked me the other day if I could make her a snapping turtle for a companion animal (she uses the UA Revised Ranger, Beast Conclave). After having watched Monster Manual and online, I haven't found anything that really worked for me.

I made the following statblock for a possible snapping turtle animal companion:

Snapping turtle

Medium beast, all alignment

Armor class 14 (natural armor)
Damage points 30 (4d8 + 12)
Speed 15 feet, swim 30 feet

begin {array} {cccccc}
text {STR} & text {DEX} & text {CON} & text {INT} & text {WIS} & text {CHA} \
16 ; (+ 3) & 8 ; (- 1) & 16 ; (+ 3) & 2 ; (- 4) & 12 ; (+ 1) & 6 ; (- 2)
end {array}

Backup jets Str +5
Meaning Passive perception 11
Challenge 1/2 (100 XP)

Hold one's breath. The snapping turtle can hold its breath for 1 hour.


Break. Melee attack with a weapon: +5 to hit, reach 5 feet, a target. Hit: 6 (1d6 + 3) piercing damage.

Headbutt. Melee attack with a weapon: +5 to hit, reach 5 feet, a target. Hit: 8 (1d10 + 3) bludgeoning damage. Deals 2 (1d4) recoil damage to the turtle. Critical failure causes 5 (2d4) damage to the turtle.

Shell Defense. The snapping turtle can retreat into its shell as an action. Until he emerges, he gains a +4 bonus to AC and has an advantage on the Force and Constitution saving throws. While in its shell, the turtle is prone, its speed is 0 and cannot increase, it has a disadvantage on the saving throws of Dexterity, and it cannot take reactions. The only action he can take is a bonus action that emerges from his shell.

Is this homebrew snapping turtle balanced as an animal companion for the UA Revised Ranger (Beast Conclave)?