Constrain movement in World Space based on drag

In a current project I need to be able to constrain the movement of placed 3d objects based on a drag operation.

So 2 steps
1-Selection
Press and hold briefly to select object

2-Movement
While continuing to press, dragging moves selected object but constrained to juts one axis, local to the object

An actual example. In an AR scene you have placed 3D picture frames on a real world wall.
You need to re-arrange these frames on the wall.
So press and hold to select a frame, then drag to constrain the movement along the real world wall.

Can anyone get me started in solving this?
What is required for each step?

Are there any existing demos or code samples that have this functionality?

Have a look at ARAnchors: AR Anchor Manager | AR Foundation | 3.0.1
And try attaching them to the ARPlane that is created for your wall. They should then maintain their position relative to the plane.

With regards to moving them: There are multiple approaches you could take, but they will all involve some sort of raycast.
You can either:

  • Raycast on the Instantiated objects itself (via Physics.Raycast()) and update the position based on the offset between that raycast and the object (in 2D)
  • Raycast on the ARPlane-GameObject that was created in your Scene when ARFoundation recognized it
  • Raycast onto the wall itself using ARRaycastManager
1 Like