12-06-2025, 09:19 AM
(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
You solved all my issues, thak you so much!