lifetime by position?

Is there a way to set a lifetime based on position, so that an object can be automatically eliminated if it's y value is less than some limit (for example).? I've got bubbles spawning from a character when underwater which float upward from the character as it swims (using an orx spawner). I'd like to kill the bubble object when it reaches the surface of the water. As it is, the bubbles continue into the air above the surface if the character is close to the surface.


  • I solved this one by making a "bubble killer" invisible object that hovers just above the water and sets the bubble's lifetime to zero when a bubble collides with it. I'm still wondering if there is a simpler orx way. It does seem some type of lifetime by position might be useful. Or a min/max [x,y,z] that kills an object outside of the specified bounds.

  • edited December 2019

    Woops, sorry for the delay as I didn't get an email notification for that post, for some reason...

    The collider is probably the most common approach, beside setting the lifetime yourself in code, when the object's been created (cf orxOBJECT_EVENT_CREATE).

    However you could do the same thing with a track, either upon creation if your bubbles have a linear speed, something like:

    TrackList       = BubbleTrack
    Surface         = (0, 200)
    0 = > Object.GetSpeed ^ #
        > Object.GetPosition ^ #
        > Get Bubble Surface #
        > - < <, > min < (0, 0), > / < < # ; min -> assumes a negative speed for bubbles going up
        > Vector.Y <, Object.SetLifeTime ^ <

    Or if you want to test every frame, in case of non-linear speed:

    TrackList       = BubbleTrack
    Surface         = (0, 200)
    0 = > Object.GetPosition ^ #
        > Get Particle Surface #
        > - < <, > Vector.Y <, > min < 0 # ; min -> assumes a negative speed for bubbles going up
        > == < 0, > if < 0 -1, Object.SetLifeTime ^ <
    Loop = true

    In both cases, in the tracks above, you could do more than just deleting your bubble based on the remaning lifetime, you could also create a new object for a visual or auditive "pop", for example.

    That being said, when the tracks are becoming too complex, you might want to simply stick with some code that would iterate over your bubbles for example, and do some logic there.

    PS: Lemme know if the tracks above are too cryptic, I'll be happy to explain them in more details. :)

  • Hi, no worries about any delay in response! Thanks much for this. It does appear cryptic at first glance but I'll look over it when I have more time and see what I can digest. I wondered if the collision testing is bad for performance, but for the amount of bubbles I have it seems to work fine. I'd be able to make the audible bubble pop sounds using collision as well, so I may end up sticking with it for now. Very interesting to see what can be done in the ini file!

  • edited December 2019

    I don't think the collision approach should matter much performance-wise.

    As for the tracks I wrote earlier, you can get more familiar with commands (they're the same you can use from the in-game console) on the wiki.
    More particularly:

    Also I guess the tracks could be simplified a bit, for example, another "detailed" version of the "test every frame" would be:

    TrackList       = BubbleTrack
    Surface         = 200
    0 = > Get Particle Surface # ; Gets the surface Y value
        > Object.GetPosition ^ #; Gets the object's position
        > Vector.Y < # ; Keeps only the Y component of the object's position
        > lt < < false, > if < 0 -1 # ; if Obj.PosY <= Particle.Surface then push 0 else push -1
        Object.SetLifeTime ^ < ; Sets object's lifetime based on the value pushed above (-1 = stay alive, 0 = die)
    Loop = true

    Which should be a bit more digest, hopefully.

    [Note that it requires the latest version of orx from the master branch as I added the command Vector.Y today. :)]

  • Thanks very much! The links to the tutorials are indeed very helpful. It will take some practice before I can get used to writing those myself.

Sign In or Register to comment.