Set up physical dragging#
Add one SoftBodyDragController to a scene object. Assign its camera, or tag the intended camera MainCamera. The controller selects a body using its simulated outline and applies a mass-aware grip. Release preserves momentum.
For a ready-made setup, open Demo/Drag/05-Drag.unity. The sample already includes the controller.
Choose an input route#
| Route | Setup |
|---|---|
| Legacy Input Manager | The controller supports mouse and touch when the new Input System integration is not installed or enabled. |
| Optional Input System | The separate ERAGANX.SoftBody2D.InputSystem assembly supplies SoftBodyPointerInput. Add it beside the drag controller to forward mouse/touchscreen events. This route requires the Input System package. |
| Custom pointer source | Convert screen positions through the controller and call its pointer methods. |
Forward a custom pointer#
| Stage | Call |
|---|---|
| Convert coordinates | drag.ScreenToWorld(screenPosition) |
| Press | drag.BeginDrag(pointerId, worldPosition) |
| Move | drag.MoveDrag(pointerId, worldPosition) |
| Release | drag.EndDrag(pointerId) |
| Disable or interrupt the input layer | drag.ReleaseAll() |
Keep pointer IDs unique while active. One pointer controls one body at a time; a second pointer can control another body. Movement positions must be in world space.
The complete DragInput.cs example shows the screen conversion and press/move/release flow. Its methods are entry points for your own input source; wire the source to them and release active drags when disabling that input layer.