- Home /
SweepTest not working from Coroutine
Very strange thing, that SweepTest just not working. That returns False all the time, in the same moment in Update that returns True. Spend so much time to find a reason..but no results Here is a code: (Position - is a structure for transform params holding)
public Position SweepCorrection (Position targetTransform)
{
print ("SweepCorrection");
RaycastHit sweepHit;
print (rigidbody.SweepTest(-transform.forward, out sweepHit, 20f));
return targetTransform;
}
That is the way how it called from Update
void Update ()
{
if (Input.GetKey(KeyCode.Space))
{
Position pos = new Position();
pos.position = transform.position;
pos.rotation = transform.rotation;
SweepCorrection(pos); //holding Space, I get True;
}
}
And here from IENumerator
public IEnumerator MoveElementInternal()
{
Ray ray;
RaycastHit hit;
while (Input.GetMouseButton(0) && !SceneSettings.Settings.OverGUI)
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
{
targetTransform = GetTargetTransform(hit);
targetTransform = SweepCorrection(targetTransform);
MoveObjectToNewPosition(targetTransform);
}
yield return null;
}
Comment