parameter based on time in vex.

   6710   6   1
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
Hi,
I was setting up a simple force that will kick in when the particles start moving too fast. and I wanted to decrease that force based on the time passed. And then it hit me…how do I measure time passed since a condition was met?
Basically I did this:
x_force = 0;
if (v_length > v_min && v_length<v_max)
    {
    x_force = 10;
    } else 
    {
    if (x_force >0)
    {
    x_force = x_force -[b]minus a little bit per time step since fist condition was met?????[/b]
    }
    }

This is a simplified version of the code but it shows where i am a bit confused.
Anyone know how to approach this? it has to do with @TimeInc right?
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
2561 posts
Joined: June 2008
Offline
I think you might need to store the time when the particles started moving too fast as an attribute on the particle. Then the code would be easier. Just subtract current time from saved time to determine your slowdown.
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
Enivob
I think you might need to store the time when the particles started moving too fast as an attribute on the particle. Then the code would be easier. Just subtract current time from saved time to determine your slowdown.
That's what I thought but how do I store the time?
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
2561 posts
Joined: June 2008
Offline
If an attribute does not exist and you assign to it, it is create automatically.
So if length is your condition to begin, mark time at that point.

I don't know, maybe something like this…
if (v_length > v_min && v_length<v_max)
{
    float success = 0;
    float saved_time = getattrib(0,"point","time_start",@ptnum,success);  // success is 0 if attribute does not exist.
    if (success == 0) {
        // Attribute does not exist, this is the first time, so let's create it.
        @time_start = @Time;
    } else {
        // Our attribute already exists so we can review it and make decisions.
        elapsed_time = @Time - saved_time
        if (elapsed_time > 0.5) {
            // Time to reduce velocity value.
        } else {
            // Waiting to put on the brakes.
        }
    }
} else {
    // Other code
}
Edited by Enivob - Oct. 13, 2016 23:45:12
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
Enivob
If an attribute does not exist and you assign to it, it is create automatically.
So if length is your condition to begin, mark time at that point.

I don't know, maybe something like this…
if (v_length > v_min && v_length<v_max)
{
    float success = 0;
    float saved_time = getattrib(0,"point","time_start",@ptnum,success);  // success is 0 if attribute does not exist.
    if (success == 0) {
        // Attribute does not exist, this is the first time, so let's create it.
        @time_start = @Time;
    } else {
        // Our attribute already exists so we can review it and make decisions.
        elapsed_time = @Time - saved_time
        if (elapsed_time > 0.5) {
            // Time to reduce velocity value.
        } else {
            // Waiting to put on the brakes.
        }
    }
} else {
    // Other code
}
Thank you anivob! I allways absolutely disregarded the success return from the point function . But here it is to the rescue. I also like the idea of recording the time within the condition. I think I may end-up creating my own attribute “active” and use it as a check box to replace the success value. That way I can continuously turn on and off the clock. Thank you for the help.
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
mmm…
I don't seem to get this to work.
I basically adapted your system to the following but the problem seems to be that in the moment I equate time_start to @Time. the time recorded is not the time in which the condition is met but actually the attribute @Time. Basically time is still counting after the status success changed.

i@state = 0;
f@time_start = 0;
if (dist < outRadius && @state == 0 )
{
    @time_start = @Time;
    @state = 1;
}

I also tried a while function but the result is the same.
Basically everything will be solve if I could record the time a condition is met.
Edited by Nicolas Heluani - Oct. 15, 2016 12:39:18

Attachments:
timer.hiplc (243.3 KB)

https://www.imdb.com/name/nm8408875/ [www.imdb.com]
User Avatar
Member
280 posts
Joined: Dec. 2015
Offline
Uff… the problem was that I was reassigning state every frame T_T(very embarrasing).

Here is the solution just in case somebody is also searching for it:

float origin = 0;
float dist = float (@P.y) - origin; 
if (dist > 2  && @state == 0 )
{
    @time_start = @Time;
    @Cd = set (1,0,0);
    @state = 1;    
}
https://www.imdb.com/name/nm8408875/ [www.imdb.com]
  • Quick Links