20-12-2021, 09:35 AM
Hello,
i have recently started to work with the Obi Package (Rope/Cloth) and am running in some trouble. It is probably a pretty simple fix/problem but i simply am unable to figure it out myself. I used the code example for spatial query which is working really perfectly as long as only one actor is in the solver. As soon as multiple actors from the same type are in the solver the position data is calculated wrong. It stays correct with the last actor in the solver though, which i find curious.
Here is a GIF of the problem
Any suggestions why this might be? Does this concern the info in the example code (We're assuming the solver only contains 0-simplices (particles))?
A follow up question would be. I plan on using multiple solvers with multiple actors in my scene and would keep the performance overhead low. What would be the best query method to check which actor/particles are near. Is the spatial query method suited for this purpose?
Any help would be highly appreciated
Best regards, Will
i have recently started to work with the Obi Package (Rope/Cloth) and am running in some trouble. It is probably a pretty simple fix/problem but i simply am unable to figure it out myself. I used the code example for spatial query which is working really perfectly as long as only one actor is in the solver. As soon as multiple actors from the same type are in the solver the position data is calculated wrong. It stays correct with the last actor in the solver though, which i find curious.
Code:
using UnityEngine;
using Obi;
public class DistanceToPoint : MonoBehaviour
{
public ObiSolver solver;
public float radius = 1;
void Update()
{
int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
var query = new QueryShape(QueryShape.QueryType.Sphere, Vector3.zero, Vector3.zero, 0, radius, filter);
var xform = new AffineTransform(transform.position, transform.rotation, transform.localScale);
QueryResult[] results = solver.SpatialQuery(query, xform);
// Iterate over results and draw their distance to the point.
// We're assuming the solver only contains 0-simplices (particles).
for (int i = 0; i < results.Length; ++i)
{
if (results[i].distance < radius)
{
Vector3 pos = solver.transform.TransformPoint(solver.positions[results[i].simplexIndex]);
Debug.DrawLine(transform.position, pos, Color.yellow);
}
}
}
}
Here is a GIF of the problem
Any suggestions why this might be? Does this concern the info in the example code (We're assuming the solver only contains 0-simplices (particles))?
A follow up question would be. I plan on using multiple solvers with multiple actors in my scene and would keep the performance overhead low. What would be the best query method to check which actor/particles are near. Is the spatial query method suited for this purpose?
Any help would be highly appreciated
Best regards, Will