Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi 7.0 ParticleAPI
#11
(10-06-2025, 08:31 AM)alicecatalano Wrote: this is always false, even when visually i can see it happens.

Note that your code will return false as long as the last particle you check is outside the bounds: you're overwriting the value of the "inBound" variable every iteration and never stopping the loop. Not sure if this is intentional or not but it sure looks wrong.

In case you want to check whether *any* particle is inside the bounds, the proper way to do it would be immediately returning true from inside the for loop as soon as you find a particle inside. Otherwise, return false at the end of the method once you've checked all particles and know none of them are inside the bounds.

kind regards.
Reply
#12
Quote:seems like i have no idea on how to convert from solver to world space. my corss areas are in the solver hierarchy.


Vector spaces are critical stuff to understand when working with any game engine, since all engines are full of them and use them constantly: object, local, world, camera, viewport, screen, etc. Unity has built-in methods to convert data between spaces. To convert a position from local to world space, use TransformPoint.

Here's your code after fixing all issues:

- Use world space for everything.
- Stop looping once you find a particle inside, don't overwrite a variable each iteration.
- Only check active particles.

Assuming crossArea.bounds is expressed in world space (it will if crossArea is a collider, as per the documentation), this will return true if any particle in the rope is inside the bounds, and false otherwise.


Code:
bool IsRopeInsideCrossArea()
    {
        if (rope.isLoaded)
        {
            for (int i = 0; i < rope.activeParticleCount; ++i)
            {
                int solverIndex = rope.solverIndices[i];
                Vector3 particlePos = rope.solver.transform.TransformPoint(rope.solver.positions[solverIndex]);
                Debug.Log($"particle {solverIndex} position {particlePos}");
          
                if (crossArea.bounds.Contains(particlePos))
                    return true;
            }
           
        }
        return false;
    }

Let me know if you need further help Sonrisa
Reply
#13
(10-06-2025, 10:26 AM)josemendez Wrote: Vector spaces are critical stuff to understand when working with any game engine, since all engines are full of them and use them constantly: object, local, world, camera, viewport, screen, etc. Unity has built-in methods to convert data between spaces. To convert a position from local to world space, use TransformPoint.

Here's your code after fixing all issues:

- Use world space for everything.
- Stop looping once you find a particle inside, don't overwrite a variable each iteration.
- Only check active particles.

Assuming crossArea.bounds is expressed in world space (it will if crossArea is a collider, as per the documentation), this will return true if any particle in the rope is inside the bounds, and false otherwise.


Code:
bool IsRopeInsideCrossArea()
    {
        if (rope.isLoaded)
        {
            for (int i = 0; i < rope.activeParticleCount; ++i)
            {
                int solverIndex = rope.solverIndices[i];
                Vector3 particlePos = rope.solver.transform.TransformPoint(rope.solver.positions[solverIndex]);
                Debug.Log($"particle {solverIndex} position {particlePos}");
          
                if (crossArea.bounds.Contains(particlePos))
                    return true;
            }
           
        }
        return false;
    }

Let me know if you need further help Sonrisa

You solved all my issues, thak you so much!
Reply