Skip to content

Grid Dragging

This asset allows you to setup a grid to snap your objects to.

TODO: Add a side-by-side comparison GIF here: one side showing free dragging and the other showing grid-snapped dragging.

Setup

  1. Create the Asset: Right-click in your Project window and select Create > DecoRat > Decorating > Grid Settings.
  2. Configure Your Grid: In the Inspector, you can set the size of your grid (e.g., 1 unit, 0.5 units) and choose which axes (X, Y, or Z) should snap.
  3. Assign it: Drag your new Grid Settings asset into the appropriate slot in your Decorating Toolkit Settings asset.

TODO: Add a screenshot of the GridSettings Inspector showing different axis configurations.

How it works

The toolkit handles grid snapping through the GridDragMotor. This motor acts as a wrapper around the standard PhysicsDragMotor.

When you move your cursor, the GridDragMotor calculates where the object would go, "pulls" that position to the nearest point on your grid, and then tells the physics motor to move the object toward that snapped spot.

API Reference

If you're looking to dive into the code:

  • GridSettings: The ScriptableObject that holds your grid configuration.
  • GridDragMotor: The implementation of IDragMotor that handles the math for snapping.