Question How to implement changes in scene variables over time?

eb123

New member
Messages
9
Reactions
3
Points
3
Hello,

I tried to find a guide and implement it myself, but I couldn't, can you help please?

I want to implement this logic (an abstract example so as not to be tied to specific plugins and variables):

I want to write two triggers:

Trigger 1 - the task starts within 10 seconds.

The variable plugin1.value1 changes linearly from 0 to 1 within 10 seconds
The variable plugin1.value2 changes along a curve from 0 to 1 within 10 seconds
The variable plugin2.value3 changes linearly from 0 to 1 5 seconds after the start for 5 seconds
At the seventh second, the plugin3.value4 variable simply changes its value from 5 to 6 (with custom if logic)

Trigger 2 - cancel task (all pending actions must be canceled)


Example Image:
1704733878535.png




I can write it in Kotlin roughly like this:

C#:
import kotlinx.coroutines.*

fun main() {
    val job = Job()
    val scope = CoroutineScope(Dispatchers.Default + job)

    scope.launch {
        val startTime = System.currentTimeMillis()
        while (System.currentTimeMillis() - startTime < 10000) {
            val progress = (System.currentTimeMillis() - startTime) / 10000.0
            val value1 = progress.coerceIn(0.0, 1.0)
            plugin1.value1 = value1
            delay(100)
        }

        startTime = System.currentTimeMillis()
        while (System.currentTimeMillis() - startTime < 10000) {
            val progress = (System.currentTimeMillis() - startTime) / 10000.0
            val value2 = Math.sin(progress * Math.PI).coerceIn(0.0, 1.0)
            plugin1.value2 = value2
            delay(100)
        }

        delay(5000)
        startTime = System.currentTimeMillis()
        while (System.currentTimeMillis() - startTime < 5000) {
            val progress = (System.currentTimeMillis() - startTime) / 5000.0
            val value3 = progress.coerceIn(0.0, 1.0)
            plugin2.value3 = value3
            delay(100)
        }

        delay(7000)
        //for example with custom logic !
        if (plugin3.value4 < 10)
        plugin3.value4=plugin3.value4*2

        job.cancelAndJoin()
        println("Task canceled")
    }

    // Trigger 2 (to cancel the task)
    val trigger2 = readLine()
    if (trigger2 == "cancel") {
        job.cancel()
    }
}

It doesn't matter how it can be implemented,using plugins, clean code, I just want to know how to do this as simply and cleanly as possible.

Thank you in advance!
 
The easiest is probably to use Timeline plugin to animate your values. Not sure about "custom logic"...because its a Timeline...it doesn't do much logic.

Another option is to combine a couple of LogicBricks, probably Blend and Delay bricks....maybe a StateMachine brick.

If you want to code, you could look at the Blend brick as an example to make your own custom brick that does precisely what you want.
 
Upvote 0
Thanks for the answer!

Yes, I looked at the timeline, and it seems that it does not suit me precisely because it does not allow for additional logic to be implemented and does not implement a state machine.

I can't do the following:
a) Own function for changing a variable
b) Change with custom condition
c) It’s not very convenient to build chains of function calls/cancellations

In fact I need a framework that implements:
A finite state machine with the ability to create states, events, transitions, conditions, etc.

On top of the state machine there should be additional “timeline++” logic for creating and managing dependent, deferred FSM events, functions for custom changes to variables, etc.

I'll dive deeper into LogicBricks - come back with the results later.
 
Upvote 0
yes, that's what I need, thanks!

I learned in detail MacGruber_Utils.cs - a useful thing that explains a lot of undocumented things.

And I implemented my own additional plugin for the functionality described above. MacGruber Thank you!
 
Upvote 0
Back
Top Bottom