5
$\begingroup$

There's so many related questions i may have missed something. But i'm trying to set a series of existing objects that start with a pre-defined location. I want them to follow the same curve - but with zero offset.

Consider the example below - The first cube starts on the curve start point, but the second point is offset. I have many more objects offset further.

Start Points

When I animate further, the second (and subsequent) objects are offset by their initial distance from the start point. Follow Curve

What I want is for the object start point to be offset, but to follow the path strictly. That is, follow with zero offset.

I also don't want to create multiple curves if I can help it.

Any suggestions?

EDIT: To clarify - the objects are converted CAD objects, so the start position is pre-defined. Calculating offsets for each object isn't practical, so what I'm looking for in a sense, is a way to automatically calculate the offset, or achieve a similar result some other way.

EDIT: Added sample blend file. Note - One object has a follow path constraint added, with a manually tweaked offset.

$\endgroup$
2
  • $\begingroup$ Suggestion. Make the single curve longer. The items have location(0,0,0). The items start at different offsets on the curve such as [0.0, 0.1, 0.2] You may want to use Python scripts or Python drivers to coordinate motion and object visibility. Please show your work if you so choose. $\endgroup$ Commented Nov 10, 2022 at 6:10
  • $\begingroup$ Location means what you see in the object panel. Location Scale Rotation are near each other in the panel. $\endgroup$ Commented Nov 10, 2022 at 6:14

4 Answers 4

5
$\begingroup$

You can use drivers for this.

Use this scripted expression here:

enter image description here

the "-.5" is basically the offset of the objects.

So for the next object use "-.4", then "-.3" and so on. (or whatever you like).

result:

enter image description here

enter image description here


or, if you are as lazy as hell as i am, you can write a python script which takes much more time to figure it out than to do it manually for 100 objects but then you could do it for 10000 objects in no time, you could do this:

  1. Create a new collections, name it "Cars".

  2. Create one object which should follow the path, give it this follow path constraint:

enter image description here

with this driver:

enter image description here

The object for the var should be the object itself.

it will throw an error because the custom property isn't defined yet - don't worry.

  1. Now copy that object as often as you want - all objects should now be in your new collection.

  2. run this script:

     import bpy
    
     def update_dependencies(ob):
         def updateExp(d):
             d.driver.expression += " "
             d.driver.expression = d.driver.expression[:-1]
         try:
             drivers = ob.animation_data.drivers
             for d in drivers:
                 updateExp(d)
         except AttributeError:
             return
    
     for i, ob in enumerate(bpy.data.collections["Cars"].all_objects):
         ob["number"] = i
         update_dependencies(ob)
         print(i, ob)
    

This script creates a custom property called "number" for each object and assigns a unique value to it (0,1,2,3...), then it updates all drivers.

Run the script and enjoy:

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks for the reply - but this still relies on having a start offset. My objects have an existing position (converted CAD geometry) - In a way, I'm looking for a way for Blender to automatically (or python-matically) calculate the offset so the original object position is maintained. $\endgroup$
    – G.H.
    Commented Nov 11, 2022 at 6:01
  • $\begingroup$ @G.H. That's an information you should have given from the start ;) Sometimes simplifying a problem leads to incorrect answers, since the solutions can differ a lot depending on the exact problem or task you want to achieve. $\endgroup$ Commented Nov 11, 2022 at 6:39
  • $\begingroup$ I used the term "existing objects that start with a pre-defined location", but I could have emphasised that point more. $\endgroup$
    – G.H.
    Commented Nov 11, 2022 at 6:56
  • $\begingroup$ @G.H. True, I've read this but wasn't sure what to do with it. I guess that's what also fueled the first comment under your question that the items must have the location (0,0,0) to follow the path correctly. You have to keep in mind that we might know how to work with Blender, but we are not familiar with the different projects and what premise each of them has. Thanks for your clarification in this case. $\endgroup$ Commented Nov 11, 2022 at 7:02
4
$\begingroup$

Suggestion.

Curve can be made longer to have different starting position visuals. All objects with Follow Path constraints can have location (0,0,0) in the object panel. The follow path constraints offset factor will have different values at their starting movement frames. Example starting offset factor .. x element of [0.1, 0.2, 0.3]. Use Python if that suits you.

enter image description here

$\endgroup$
3
$\begingroup$

There is no need to create other curves or make the curve longer, no need for Python or drivers etc. I guess the way you are using it might be wrong.

First of all, to have the cube follow on the curve, it has to be cleared from any location transformation - so press Alt+G to set it back onto the world's center.

Now to place it behind the other cube, change the Offset value in the Follow Path constraint to a positive value. You don't have to make the curve longer, the cube will just be moved straight in the elongated direction of the curve. Here are three cubes on a curve, one with offset 0, the next offset 15 and the third has an offset of 30:

follow path setup

So you might wonder why the offset is a positive value to move out of the curve and why moving along the curve needs negative values to get to the end. Also it doesn't seem as if the values 15 or 30 represent any distance in Blender units which the cubes are offset.

The reason is the following: if you now select the curve and look into the Curve Properties, there you will find the Path Animation options. By default the settings are Frames = 100 and Evaluation Frame = 0.000 which means, and object needs 100 Frames to travel from start to end of the curve. And the Evaluation Time at 0 means, you are now at the starting point. And there is the cube with Offset = 0.

path animation

To see what the offset now actually means, I change the Evaluation Time value at first to 100. As it was to be expected, the first cube is now at the end point (I've enabled X-ray mode to see through):

ev time 100

But if I now set the Evaluation Time to 115, the second cube is at the end point of the curve - this the offset 15 that is set in the constraint. The third cube will then reach the endpoint at 130 because of its offset 30:

ev time 115

How far the distance of a cube with offset along the curve is depends on two values: the Offset in the Follow Path constraint and the Frames value in the Path Animation settings of the curve.

For example, if I change Frames from 100 to 20, the three cubes are much further apart from each other although I didn't change the Offset values in the constraint:

frames 20

The reason is, since they only need an Evaluation Time of 20 to get from start to end, they need to be much further away to keep the time offset of 15 and 30. So with Frames = 20, at Evaluation Time = 20 the first cube with no offset reaches the endpoint:

ev time 20

And like before, the second cube reaches the end at Evaluation Time + Offset, that's 20 + 15 = 35, and the third at 20 + 30 = 50:

ev time 35

This means, to move the cubes along the curve you can use Path Animation in the Curve Properties. By animating the Evaluation Time you move them along the curve simultaneously, keeping the distance that's given by the offset value. If you want them to move at different speeds you can additionally animate the Offset values in the constraints.

Animating the Evaluation Time however is a bit tricky. It gets animated when you click on Animate Path in the constraint settings. In this moment, it gets an F-curve Modifier which uses the Frames setting to determine the linear movement.

If Frames is set to 100, this means that the animation will start at frame 1 and at frame 1 + 100 = 101 it will reach Evaluation Time = 100, the end point of the curve. Of course you can modify this later on, but it isn't as obvious as standard keyframe animation at first.

Here's for some examples. You might not be so flexible with the F-curve Modifier as with keyframes, but you can do some fancy stuff as well. First the basics, the initial animation that is created gives a linear movement using this formula:

$$y=a\cdot x^1+\text{ coefficient}$$

with $a$ being the value you enter in the $x^1$ field, which is the multiplier for the frame number $x$ and of course the coefficient which is entered in the according field. The resulting $y$ is the Evaluation Time.

linear formula

This standard linear motion looks like this:

linear motion

If the linear motion is too boring, you can for example set the Order in the F-curve Modifier to 2. Now you can have a quadratic equation for the motion, in my example I used this formula:

$$y=0.01^2-0.01$$

quadratic formula

This results in a slowly speeding up motion:

quadratic motion

If you want to be more crazy, you can also animate the influence of the constraint on the cubes. I've done this for the third one in this example. It starts with a constraint influence of 0, which let's the cube sit in the world center. With increasing influence, it starts to move towards the curve.

growing influence

Yes described earlier, the cube has to be in the world's center to make sure it sits on the curve instead of moving some away from it.

But what if you don't want the cube to start from the center? You can use a Copy Location constraint and have it attached to some empty for example. Then you keyframe the influence on this constraint. At first with an influence of 1, the cube stays in the same location as the empty. With a decreasing influence it moves back towards the center. If you now increase the influence of the Follow Path constraint, it moves from the empty back onto the curve. This can look like this:

moving from empty to curve

//EDIT: As you've explained in the comments, your cubes sit at locations off the center initially and you need to get them onto the curve. Instead of having cubes in the world's center and letting them start from empties at different locations, you can do it the other way around. The good thing is, you only need one empty for all cubes since they all have to end up in the world's center.

In this example, there is an empty at (0,0,0) while two cubes have original locations off the center, one at (-10,-10,0), the other at (5,-8,0). Both have a Copy Location constraint targeting the empty and start with an Influence of 0, slowly increasing to 1 which pushes them into the world's center and therefore onto the curve:

center empty

$\endgroup$
5
  • $\begingroup$ This is a huge answer - kudos for the effort! However, it doesn't really solve the problem. I know I can use an offset, but the key part of the problem is the pre-existing position. In my case, it's geometry converted from a CAD model, so the start locations are defined, and not easily converted to "offset" values. $\endgroup$
    – G.H.
    Commented Nov 11, 2022 at 5:58
  • $\begingroup$ Well, at the end I gave an example where you start with an offset given by the empty and with decreasing influence the cube moves to the world center, and therefore sits correct on the curve. You can do it the other way round, the cube sits on its original location and an empty is in the center. Start with influence 0 and increase it to 1 to get the cube in the center resp. onto the curve. The advantage is, you can use one empty for all cubes, no matter where they are. To get this automated I'm not the right person. $\endgroup$ Commented Nov 11, 2022 at 6:56
  • $\begingroup$ Hmmmm... so if the empty were aligned with the start point, that might have the desired effect... I'll look into that more. $\endgroup$
    – G.H.
    Commented Nov 11, 2022 at 6:58
  • $\begingroup$ @G.H. Maybe I'll edit an example at the end of this answer. $\endgroup$ Commented Nov 11, 2022 at 7:03
  • $\begingroup$ Have a look, that's what I meant. For automation processes I guess @Chris will be more suited since he is better at drivers and python than I am. $\endgroup$ Commented Nov 11, 2022 at 7:21
1
$\begingroup$

This might be on the wrong track.. but would this GN group help?

It takes a collection of objects along X, (each with their own origin) and pushes them down the modified curve-path by Offset, disappearing the objects when they go off either end.

enter image description here

.. for this behaviour:

enter image description here

.. which may need tweaking to your requirements.. call back, if this looks like a possible way to go.

$\endgroup$
2
  • $\begingroup$ This could work... It would require setting a time start point offset such that the blue cubes are all on the line in the same arrangement... E.g. rather than starting at frame 0, start at (say) frame 50... $\endgroup$
    – G.H.
    Commented Nov 11, 2022 at 12:43
  • $\begingroup$ Hi @G.H. ! I'm not clear on what your input geometry might be... CAD-derived objects with their own origins? Aligned? You could offset objects by f(Index) ..Share a sample if you like, on blend-exchange.com $\endgroup$
    – Robin Betts
    Commented Nov 11, 2022 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .