How can I control the speed at which a loop loops based on an outside variable?

Alright, So i'm using an animation program. In this program I've simulated a particle system. The particles are flying around at different and varying speeds. I've attached birds to the particles and I want to be able to control each bird's flapping animation based on its velocity; so birds moving faster will be flapping faster.

Initially, the bird's flapping animation is controlled by a parameter that goes from 0 to 100%. So not only do I need to drive the speed at which the animation goes from 0 to 100%, I need to set it on a loop so once it reaches 100%, it loops back to 0%. I'm extremely new to code so I don't think it would be wise for me to even provide a jumping off point, not that I could. Many thanks for any efforts.
You need to understand the difference between (or equivalence of) frames per second and ticks per second.

Frames per second (framerate, fps) is how many times per second you update the display of your game or application. Higher framerate appears visually smoother.

Ticks per second is how many times per second you update the logic of your game or application (e.g. moving objects based on trigonometry, changing which animation frames are currently displayed, etc).

Sometimes, a tick and a frame are one in the same: you update game logic and then draw it right away. Other times, such as with Minecraft, a ticks and frames are unrelated to each other. Minecraft uses 20 ticks per second and allows the framerate to be whatever your computer can handle or whatever you limit it to (even if it is less than the ticks per second).

With animations, you need to consider both factors - if the framerate is higher than the tick rate, you may want to create smooth transitions between the previous tick and the next tick. You might also be going for a retro style where the animations of various things are much less than either your framerate or tick rate.
I am a bit confused, how did you implement a particle system inside an animation program and at the same time you say you are new to code?

If its not coded, how do you plan to make the code you are going to write interface with the animation program?
Hi @shoyoninja. There is a node-based system with gui in the program Cinema 4D called xpresso. There's a "C.O.F.F.E.E" node that allows you to connect variables and enter code to control them. It uses its own language but it's similar to C++.
Last edited on
Thanks, @LB, that's useful. In my program there's a 'time' node that outputs seconds which can be remapped to frames. I was planning on using that as a variable to drive the loop. I guess I should have mentioned that.
Ok... The scope is quite different then.

The birds that you attached, are them already in a kind of node in your program? How do you access their data on the code?

If you wanted to print text on the screen, how would the code for that go on the "C.O.F.F.E.E" node? How does a Hello World looks like?
I can represent the bird with a node. All parameters can drive and be driven. I only need to worry about one bird with this function. The bird only has one parameter I need to drive and it has a value range of 0% to 100%, just to reiterate. I can output any of its information from the node, such as velocity etc.

No variables have to be initialized, because they are provided and already have numbers assigned. Instead of initializing a variable, a node (a 'time' node, say) is added to the node system. I can connect the output of the time node into an input port of the COFFEE node. This is how variables are 'initialized.' They can then be referred to in the script.

The languages are similar so if you can give me c++ code, I can do the conversion work myself. But here is the C.O.F.F.E.E. language site if you want to look at it. There's a hello world at the bottom of the page.

https://developers.maxon.net/docs/Cinema4DCOFFEESDK/index.htm

More documentation:
https://developers.maxon.net/docs/Cinema4DCOFFEESDK/index.htm
Last edited on
Ok, Ive checked the sources.

So, basicly, you will NOT create loops inside the script. The loop is already going on Cinema 4D, and every frame where your xpresso node appears, will call the function main() you define in there (if you created a loop for an animation in there, you would stall everything else in the scene until your animation was done).

My suggestion is that you use the movement speed of the Bird objects on the scene, to control the animation speed, which from what I see on cinema 4D is defined as "Time" in number of frames/second.

So, a scenario would be that you will have to calculate the speed of your birds, maybe from keeping track of their coordinates in relation to time. And, based on that speed, increment the number of frames/second drawn on each object.

You will iterate through the objects and do the changes, you will not do loops and try to animate them inside the loop (the animation loop is controled already by the host).

Which is both considerably simpler than what you had in mind, but also, totally different :P. So I strongly suggest you play around with it a bit, try to link those values from each bird to your node first, maybe there is a way to do a simple direct control (if you have access to its screen speed, you could simple divide it by a given factor and use it as the animation frame speed).
Last edited on
Thanks, @shoyoninja. You probably saved me a lot of time with the loop tip, but unfortunately the loop isn't already going in the program. It has to be driven with either keyframes (classical animation) or a variable.

I've decided to take an easier and less technical route to bring the required skill level down a few notches. What I've done instead was animate the whole bird along a path with the flap animation being driven by how far along the path the bird is. The big down side to this is that now I have to create each bird and each path instead of them generating themselves with a particle system. This route also allows me to use gui options to loop the flap animation.

I really appreciate you taking the time to help me though!

And I'm still very interested to see how this would generally look in C++, given the variables.
Last edited on
Topic archived. No new replies allowed.