Contemplating a MEL script...
So I have a concept I'm working on animating and the more I think about it the more I want to control the instanced particles (fish) with a combination of dynamics and scripting.
Bear with me as I think this through on here as my way of taking notes for myself. I need the particles(fish) to move at a variety of speeds and collide with the interior of the fish tank which should cause them to turn and swim the other direction. The particles obviously need to maintain their correction orientation in the direction of their momentum but that should be easily arranged by an aim-direction option in the instancing node. The trick is to not only give the particles their own individual velocities but to allow them to change that velocity at random intervals and have that change in velocity also adjust the speed of their swim cycle animations. I also need them to randomly choose to swim up and down on the Y axis so they aren't constantly swimming on a horizontal plane.
All that being said... I think what needs to be done is that I need to find the proper syntax to connect the current velocity of a particle on a per particle level to the speed of the instanced geometry's animation. I'm guessing there's a get attribute call that can provide me the per particle velocity value which I can then use to multiply against the speed of the animation on the instanced geometry. I'm hoping that by speeding up the particle's age it will also increase the animation speed but I may have to resort to using an instanced object sequence as opposed to a bone driven deformable fish as I'm more certain that the object sequence would behave as I intend.
So the other issue is to find a way to drive the particles to swim in a particular direction for a while and then change direction either due to a collision with the tank wall or at random and all at randomized speeds. I believe the orientation of the particles should take care of itself when colliding with a wall so I could simply rely on the collisions to turn the fish around but then they may look silly just swimming from wall to wall with no randomness to their pattern. I think I'll come back to that issue later though. I think my real question is whether or not giving them an value in a directional impulse field will affect them in world space or in local space. It would be ideal if I can have give them an impulse in their local space as then it'd be a simple matter of pointing them in the proper orientation and setting them free and when they collide with something they'll turn and continue on in the new direction. Then it'd simply be a matter of adding a random multiplier value to the impulse to change up the speeds. Well I suppose I couldn't just throw the random value directly onto the impulse... I guess I'd need to have the impulse value applied in spurts so that the fish isn't jerking around like an epileptic. Maybe if I can specify that at certain values specified in the particles age that the random value gets applied to the impulse. Say if I said any time the particle's age equals a multiple of 20 then it applies a value to the impulse within a random range. I suppose if I set the interval far enough apart I could even make the random range go from negative to positive to give the fish the option to change direction randomly (assuming this doesn't mess up my particle oriention) I suppose it wouldn't hurt to specify an amount of time to continue applying this momentum before allowing it shut off and allow it's momentum to die before the next spurt of impulse. I suppose it'd be smart to also include my random value in the Y axis to this series of motions as well. That would definitely be a random range going from negative to positive so as to allow for upwards or downward swimming.
Ok... so I'm going to attempt to tackle this one piece at a time and then when I find a solution I'll possibly add variables to allow for different sorts of fish to swim differently.
Bear with me as I think this through on here as my way of taking notes for myself. I need the particles(fish) to move at a variety of speeds and collide with the interior of the fish tank which should cause them to turn and swim the other direction. The particles obviously need to maintain their correction orientation in the direction of their momentum but that should be easily arranged by an aim-direction option in the instancing node. The trick is to not only give the particles their own individual velocities but to allow them to change that velocity at random intervals and have that change in velocity also adjust the speed of their swim cycle animations. I also need them to randomly choose to swim up and down on the Y axis so they aren't constantly swimming on a horizontal plane.
All that being said... I think what needs to be done is that I need to find the proper syntax to connect the current velocity of a particle on a per particle level to the speed of the instanced geometry's animation. I'm guessing there's a get attribute call that can provide me the per particle velocity value which I can then use to multiply against the speed of the animation on the instanced geometry. I'm hoping that by speeding up the particle's age it will also increase the animation speed but I may have to resort to using an instanced object sequence as opposed to a bone driven deformable fish as I'm more certain that the object sequence would behave as I intend.
So the other issue is to find a way to drive the particles to swim in a particular direction for a while and then change direction either due to a collision with the tank wall or at random and all at randomized speeds. I believe the orientation of the particles should take care of itself when colliding with a wall so I could simply rely on the collisions to turn the fish around but then they may look silly just swimming from wall to wall with no randomness to their pattern. I think I'll come back to that issue later though. I think my real question is whether or not giving them an value in a directional impulse field will affect them in world space or in local space. It would be ideal if I can have give them an impulse in their local space as then it'd be a simple matter of pointing them in the proper orientation and setting them free and when they collide with something they'll turn and continue on in the new direction. Then it'd simply be a matter of adding a random multiplier value to the impulse to change up the speeds. Well I suppose I couldn't just throw the random value directly onto the impulse... I guess I'd need to have the impulse value applied in spurts so that the fish isn't jerking around like an epileptic. Maybe if I can specify that at certain values specified in the particles age that the random value gets applied to the impulse. Say if I said any time the particle's age equals a multiple of 20 then it applies a value to the impulse within a random range. I suppose if I set the interval far enough apart I could even make the random range go from negative to positive to give the fish the option to change direction randomly (assuming this doesn't mess up my particle oriention) I suppose it wouldn't hurt to specify an amount of time to continue applying this momentum before allowing it shut off and allow it's momentum to die before the next spurt of impulse. I suppose it'd be smart to also include my random value in the Y axis to this series of motions as well. That would definitely be a random range going from negative to positive so as to allow for upwards or downward swimming.
Ok... so I'm going to attempt to tackle this one piece at a time and then when I find a solution I'll possibly add variables to allow for different sorts of fish to swim differently.