23-10-2017, 06:57 AM
Heading off to work now too, but will definitely check that out later!
I am not checking for collision at the moment but once the GrabStrength of the hand is strong enough I find the nearest particle and check if the distance is below a certain threshhold for grabbing. Pretty much like this:
This is done "once per grabbing" so should be ok I guess, but maybe using Colliders would be better...
I am not checking for collision at the moment but once the GrabStrength of the hand is strong enough I find the nearest particle and check if the distance is below a certain threshhold for grabbing. Pretty much like this:
Code:
IEnumerator GrabParticle(ObiParticleHandle currentHandle)
{
if (actor.InSolver)
{
actor.Solver.RequireRenderablePositions();
yield return null;
float currentSqrMagnitude = float.MaxValue;
float smallestSqrMagnitude = float.MaxValue;
float smallestMagnitude = float.MaxValue;
int currentIndex = 0;
for (int i = 0; i < actor.invMasses.Length; i++)
{
currentSqrMagnitude = (actor.GetParticlePosition(i) - currentHandle.transform.position).sqrMagnitude;
if (currentSqrMagnitude < smallestSqrMagnitude)
{
smallestSqrMagnitude = currentSqrMagnitude;
currentIndex = i;
}
}
smallestMagnitude = Mathf.Sqrt(smallestSqrMagnitude);
if (smallestMagnitude < user.clothManipulate.grabThreshold)
{
currentHandle.AddParticle(currentIndex, actor.GetParticlePosition(currentIndex), cachedInvMass);
}
actor.Solver.RelinquishRenderablePositions();
}
}