Announcement

Collapse
No announcement yet.

Is it possible to play multiple animations simultaneously? [ WITH SOLUTION ]

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is it possible to play multiple animations simultaneously? [ WITH SOLUTION ]

    I'm working on my Gunship chopper craft and want to trigger various animation sequences during different stages of flight. Here's a quick render so you what it looks like and get an idea of what I want to do:



    For instance, on takeoff, I want the landing gear to retract and the speedbrakes (those panels on the engines) to fold back. On landing, the gear comes out and the panels rotate out again.

    Now, the speedbrakes should activate during different stages of flight. If you press the "back" button, they pop out. If you press left, the left speedbrakes pop out. Et cetera, et cetera, et cetera...

    The problem I'm having is that I can't call multiple anims at once. For instance...

    PHP Code:
            PlayAnim('lgdown');   // LandingGearDown
            
    PlayAnim('lsbopen');   // LeftSpeedBrakeOpen
            
    PlayAnim('rsbopen');   // RightSpeedBrakeOpen 
    ...results in only the Right speed brake popping open. No matter what arrangement I choose, it always plays the *last* animation.

    Now, if I combine all the motions into 2 separate animations called "takeoff" and "landing" they work fine. However, that also means I have to create additional animations for "left turn open", "left turn close, "right turn open", "right turn close", "air braking open", "descent open".... you get the picture.

    What I'd like is to just have 6 animations: Left & Right Speedbrake open and close, and landing gear up and down. I could just trigger the speedbrake sets individually for flight states, and combine them with the landing gear for takeoff and landing.

    The long and short: Is there any way to get multiple animations to play simultaneously in what I guess could be called animation "combos"?

    #2
    It certainly is possible! You want to use the AnimBlendParams function to set a particular animation channel to only affect a particular bone and its children. Here's an example, playing two animations on channels 0 and 1:
    Code:
    AnimBlendParams(0, 1.0,,, 'Bone_LTrack');
    PlayAnim('LeftTrack',,, 0);
    
    AnimBlendParams(1, 1.0,,, 'Bone_RTrack');
    PlayAnim('RightTrack',,, 1);
    You might also find the SetAnimFrame function useful, as it allows precise control over the animation, so you can run forwards and backwards at any speed or pause the animation as you please.

    Comment


      #3
      And THAT is why you rock, sir!

      Very handy stuff. I'll be sure to give it a whirl right away.

      Comment


        #4
        Actually, could you break it down a little further?

        Let's say I wanted to play the following animations simultaneously:

        LSBopen (Left speedbrake open)
        RSBopen (Right speedbrake open)
        LGdown (Landing gear down)

        Would I then use the following:
        PHP Code:
        AnimBlendParams(01.0,,, 'TrackLeftSB');
        PlayAnim('LSBopen',,, 0);

        AnimBlendParams(11.0,,, 'TrackRightSB');
        PlayAnim('RSBopen',,, 1);

        AnimBlendParams(21.0,,, 'TrackLGdown');
        PlayAnim('LGdown',,, 2); 

        Comment


          #5
          Okay - I tried the above and it didn't work... It just played the last anim in the sequence (LGup/LGdown in this case). Any ideas?

          Here's the full code I'm using for the takeoff and landing anims:

          ---------------------------------------------------------------------
          // Play TakeOff Animation
          function KDriverEnter(Pawn P)
          {
          AnimBlendParams(0, 1.0,,, 'TrackLeftSB');
          PlayAnim('LSBclose',,, 0);

          AnimBlendParams(1, 1.0,,, 'TrackRightSB');
          PlayAnim('RSBclose',,, 1);

          AnimBlendParams(2, 1.0,,, 'TrackLG');
          PlayAnim('LGup',,, 2);

          //PlayAnim('lgup');
          //PlayAnim('lsbclose');
          //PlayAnim('rsbclose');

          Super.KDriverEnter(P);
          }

          // Play Landing Animation

          function bool KDriverLeave (bool bForceLeave) {

          if (Super.KDriverLeave(bForceLeave)) {

          AnimBlendParams(0, 1.0,,, 'TrackLeftSB');
          PlayAnim('LSBopen',,, 0);

          AnimBlendParams(1, 1.0,,, 'TrackRightSB');
          PlayAnim('RSBopen',,, 1);

          AnimBlendParams(2, 1.0,,, 'TrackLG');
          PlayAnim('LGdown',,, 2);


          //PlayAnim('lgdown');
          //PlayAnim('lsbopen');
          //PlayAnim('rsbopen');

          return true;
          } else {
          return false;
          }
          }

          Comment


            #6
            Never mind! Figured it out. Thanks!

            Comment


              #7
              Mind sharing the solution with us?

              Comment


                #8
                Yes - of course! I was running out to catch a plane at the time of my last posting on this thread - didn't have time to go into particulars.

                Basically, I have 3 main animations: LeftSpeedbrake open/close, Right Speedbrake open/close, and Landing Gear up & down. The skeletal structure is as follows:


                Here's the code for the takeoff animation:
                PHP Code:
                // Play TakeOff Animation
                function KDriverEnter(Pawn P)
                {
                AnimBlendParams(01.0,,, 'EngineLeft');  
                PlayAnim('LSBclose',,, 0);

                AnimBlendParams(11.0,,, 'EngineRight');
                PlayAnim('RSBclose',,, 1);

                AnimBlendParams(21.0,,, 'LGLeft');  
                PlayAnim('LGup',,, 2);

                AnimBlendParams(31.0,,, 'LGRight');  
                PlayAnim('LGup',,, 3);

                     
                Super.KDriverEnter(P);
                     
                //This tells the function to execute any code in KDriverEnter()
                 
                in Classes above this oneso KDriverEnter in ONSVehicle which 
                is a Super 
                class of this class would then be executed
                 If 
                you want your code to execue affterthen put it after

                ======================================

                The way it works is:[list=1][*] AnimBlendParams is used to target a specific bone and assign that bone a channel (0,1,2,3, etc.). All the children of that bone are therefore contained within that channel. In the line "AnimBlendParams(0, 1.0,,, 'EngineLeft');", this targets the EngineLeft bone and all children underneath - including Speedbrakes 1-4 - and places them on channel "0". [*]That way, when the subsequent "PlayAnim('LSBclose',,, 0);" function is called, it only animates those particular child bones - because they are *children* of EngineLeft.[*]The next set ("AnimBlendParams(1, 1.0,,, 'EngineRight');") places EngineRight and its children on channel "1". So on and so forth.[*]One thing to keep in mind for different animations: the landing gear animation in Maya animates left and right landing gear struts (LGLeft and LGRight) simulteneously. However, since AnimBlendParams targets specific bones and their children (and targeting root would affect the whole skeleton), we need to do the LGup animation twice - once for each strut.[/list=1]

                Comment

                Working...
                X