5
$\begingroup$

I have an object (say the default cube) and I want to limit its movement along the x-axis only, in integer increments of 1m. How can I achieve this using only object constraints if possible (without snapping, without keyframes, etc)?

For example, in this case the cube can only have the coordinates {0, 0}, {1, 0}, {2, 0}, ..., {inf, 0}, and no float numbers in between, only integers.

The problem if I use the Limit Location Constraint in Blender for example, is that the object can have any non integer value between {lower limit, higher limit} which is not desirable.

asked16 hours ago
Ifma's user avatar
New contributor
Ifma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.Check out ourCode of Conduct.
$\endgroup$
1
  • $\begingroup$Why do you need this? What's the context? What are you doing?$\endgroup$Commented15 hours ago

2 Answers2

4
$\begingroup$

If the "location" of the object is not important for later use, you can use geometry nodes to offset the geometry back to a round position with a custom step size.

Nodes

If the location will be important later, however, then you may use the same geometry nodes to control a mesh that has a single vertex at 0,0,0. Then you parent your target object to this vertex via vertex parent.

Result

answered15 hours ago
Daniel Möller's user avatar
$\endgroup$
3
$\begingroup$

You could do this with drivers. You need to add drivers for location x, y and z, each right-clicking and choosing Add Driver:

enter image description here

The expression isround(self.location.x) and similarlyself.location.y and then.z

enter image description here

Note that Auto-Run Python Scripts needs to be enabled for this.

It is dangerous to enable Auto-Run Python Scripts

Make sure to exclude your downloads paths or any paths that you may download .blend files to. Malicious software in .blend files is popular these days.

enter image description here

answered15 hours ago
Martynas Žiemys's user avatar
$\endgroup$
5
  • $\begingroup$Just keep in mind this is a dependency cycle and expect some quirkiness as a result :D$\endgroup$Commented15 hours ago
  • $\begingroup$@MarkusvonBroady, it makes sense, but do you know some specific cases, where it becomes a problem? It works fine with transform operators and it works fine with hierarchy. I cannot find any cases where it becomes a problem.$\endgroup$Commented15 hours ago
  • 1
    $\begingroup$I played with similar techniques, one problem I remember is that if I moved the object, but then cancelled the movement with a right-click, something wrong would happen, I don't remember what, I think it just wouldn't update properly. No idea if this is still the case.$\endgroup$Commented15 hours ago
  • $\begingroup$It's a good idea to keep an eye on it, but as far as I can tell it should work fine mostly...$\endgroup$Commented15 hours ago
  • $\begingroup$Oh, and sorry, I only now noticed the question asked about X axis only, so I don't make much sense talking about other axis, but... it will obviously work for one axis as well.$\endgroup$Commented15 hours ago

You mustlog in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.