Brainstorm about animation cycle

Hello everybody,

I have a container crane like the ones in rotterdam.
This crane is build up in 5 models

Crane
Grabbinggear holder
Grabbinggear
Hooks on the left side (grabbinggear)
Hooks on the right side (grabbinggear)

I need an animation that will do the following:

  • Lower the grabbinggear
  • lock the hooks on the left and right side of the grabbinggear to a container
  • Lift the grabbinggear
  • Move the grabbinggear holder with the grabbinggear and container to the middle of the crane
  • Lower the grabbinggear
  • unlock the hooks

Ps. I could determine the distance of each model in each animation

In JME I have a update method, but I don’t want to work with a lot of if statements and a time variable that counts up…
I could give the code I made already but believe me, you don’t want to see that… :frowning:

Could anybody give me a clue about a better solution or example?

Thnx in advance

As you don’t seem to want to just make one big animation in blender I take it that the locations and times are different each time this happens? Then you will have to do what you basically suggest, which is connting the time for animations and then triggering another one. Basically this is a “finite state machine”, I’d suggest looking into this concept and then making a simple base class for each state instead of separate “if’s”.

Thnx for the fast reply!

The location is different everytime, but that doesn’t matter because I use move, or otherwise the localTranslation + new translation.
The time does only change between the animations, the time needed for a animation to complete is always the same.

This is the animation I want to show (I know it’s some terrible coding):

[java]@Override
public void simpleUpdate(float tpf) {

    if(time >= 0 && time < 2.5f) {
        grabbingGear.move(0, -0.01f, 0);
        hookRight.move(0, -0.01f, 0);
        hookLeft.move(0, -0.01f, 0);
    }
    if(time >= 2.5f && time < 2.8f) {
        hookRight.move(0, 0, 0.01f);
        hookLeft.move(0, 0, -0.01f);
    }
    if(time >= 2.8f && time < 14) {
        grabbingGear.move(0, 0.01f, 0);
        hookRight.move(0, 0.01f, 0);
        hookLeft.move(0, 0.01f, 0);
        container.move(0, 0.01f, 0);
    }
    else if(time >= 14 && time < 53) {
        grabbingGearHolder.move(0.01f, 0, 0);
        grabbingGear.move(0.01f, 0, 0);
        hookRight.move(0.01f, 0, 0);
        hookLeft.move(0.01f, 0, 0);
        container.move(0.01f, 0, 0);
    }
    else if(time >= 53 && time < 64.2f){
        grabbingGear.move(0, -0.01f, 0);
        hookRight.move(0, -0.01f, 0);
        hookLeft.move(0, -0.01f, 0);
        container.move(0, -0.01f, 0);
    }
    else if(time >= 64.2f && time < 64.5f) {
        hookRight.move(0, 0, -0.01f);
        hookLeft.move(0, 0, 0.01f);
    }
    else if(time >= 64.5f && time < 67) {
        grabbingGear.move(0, 0.01f, 0);
        hookRight.move(0, 0.01f, 0);
        hookLeft.move(0, 0.01f, 0);
    }
    else if(time >= 67 && time < 75.2f) {
        grabbingGear.move(0, 0.01f, 0);
        hookRight.move(0, 0.01f, 0);
        hookLeft.move(0, 0.01f, 0);
    }
    
    time += 0.01f;
}[/java] 

I think this is what you mean:

[java]private void lowerGear(float time) {

    float y = 10.9f / time; // distance divided through execute-time
    
    if(200 < time) {
        grabbingGear.move(0,-y,0);
        hookRight.move(0,-y,0);
        hookLeft.move(0,-y,0);
    }
}[/java] 

Is this the right way?
And how should I call these methods, because I don’t want to execute all methods at the start.

Did you already look into FSMs? Maybe you can find some java examples, you seem to have to learn a bit about object oriented programming still. All your ifs and time checks would be done in the base class so you’d only have to change some time variable and write the actual check once for example.

I don’t think a FSM is really needed, because it isn’t that complex (correct me if I am wrong).

I think this is more or less what you mean, except for the update method, that should be more efficient but I don’t know how ):
The method lowerGear is an example of a method I could use, ofcourse I would create a different class for these methods.

[java]@override
public void simpleUpdate(float tpf) {

    if(time <= 200)
        lowerGear(200);
    
    time += 1;
}

private void lowerGear(float time) {
    
    float y = 10.9f / time; // distance divided through execute-time
    
    if(200 < time) {
        grabbingGear.move(0,-y,0);
        hookRight.move(0,-y,0);
        hookLeft.move(0,-y,0);
    }
}[/java]

When I alter the code a little I get the code below, the problem is that every method will be called no matter if it is needed or not…

[java]@override
public void simpleUpdate(float tpf) {

    lowerGear(0,200);
    
    time += 1;
}

private void lowerGear(int start, int end) {
    
    float y = 10.9f / time; // distance divided through execute-time
    
    if(time >= start && time < end) {
        grabbingGear.move(0,-y,0);
        hookRight.move(0,-y,0);
        hookLeft.move(0,-y,0);
    }
}[/java]

Your code makes no sense to me. Why do you have a time variable but don’t correlate it to tpf? FSMs are not complicated at all but your thinking is somehow. Idk if I can help you.

This may already do what you want to do:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:cinematics
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:motionpath

Also, (and perhaps otherwise) you may want to rename your time variable since it isn’t actually time. It’s centiframes or something (1 unit = 100 frames) and has no real relation to time at all.

Thnx for both replies.

I will look into the FSMs some more.
The example of motionpath is a very nice alternative, thnx!