Notifications
Clear all

[Closed] Travel trought 4 position

Hi

If i have 2 positions and i like an object travel from P1 to P2 i can write like this way


    Animate on
    (
        for t in 0 to 100   do
        (
                at time t
                (
                    vector_01 = (P2.pos - P1.pos)
                    Travel = ((normalize Vector_01) * (((length Vector_01)/100)*t)) + P1.pos
                    $Teapot001.pos = Travel
                )            
        )
        
    )    

But if i have P1 p2 p3 p4 as four position , how to rewrite this code the way taht the teapot travels from P1 to p2 then p2 to p3 then to p4

Thanks in advance

4 Replies

Isnt it much easier to have a position constraint with 4 targets and simply animate the weights to get the needed animation ?

or a path constraint to a linear path with 4 knots

huh ? but isn’t this the scripting section and so the OP wants to script it ?

you can script both solutions, the spline solution can be done in a similar way to op original script


(
    fn GenerateSplineShape p1 p2 p3 p4 =
    (    
        local sp = splineShape();
        addnewSpline sp;
        addKnot sp 1 #corner #line p1;
        addKnot sp 1 #corner #line p2;
        addKnot sp 1 #corner #line p3;
        addKnot sp 1 #corner #line p4;
        updateShape sp;
        sp;
    )

    delete geometry
    delete shapes
    
    theshape = GenerateSplineShape [100,100,0] [200,200,0] [300,100,0] [100,0,0]
    theteapot = teapot();    

    Animate on
    (
        for t in 0 to 100   do
        (
            at time t
            (
                theteapot.pos = pathInterp theshape 1  (t/100.0)
            )
        )
    )
)