- Home /
Question by
IrisWillaert · Oct 30, 2020 at 07:04 PM ·
raycastvector3lerphit
Raycast hit skips 1 if statement at hit
Hi, I'm pretty much a beginner and need some help with my lerper script. My script lerps a cube forward and backward when the cub hits the collider. I'm using a raycast to detect the collision. This works fine for the first hit but does nothing when the second collision occurs but again works on the next hit and so on. I can't seem to find the problem with my script. Any ideas? Thank you so much!!!
public void Update()
{
if (hasEntered)
{
timeElapsed += Time.deltaTime;
transform.localPosition = Vector3.Lerp(startPosition, endPosition, (timeElapsed / lerpTime));
if (ev.steps == 3)
// for (int i = 2; i < ev.steps; i++)
{
timeElapsed2 += Time.deltaTime;
transform.localPosition = Vector3.Lerp(endPosition, startPosition, (timeElapsed2 / lerpTime2)); /
}
}
if (Apply)
{
RaycastHit hit;
Ray ray = new Ray(Target.position, Vector3.right);
Debug.DrawRay(Target.position, Vector3.right); /
if (Physics.Raycast(ray, out hit, ModulationRayCast))
{
if (hit.collider.tag == "Midstance" && hasHit == false )
{
Debug.Log("hit");
hasHit = true;
if (hasEntered)
{
Debug.Log("second hit");
hasEntered = false;
timeElapsed = 0f;
timeElapsed2 = 0f;
}
else
{
hasEntered = true;
Debug.Log("worked");
}
}
if (hit.collider.tag == "IK" ) /
{
hasHit = false;
Debug.Log("ik");
}
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613014913im_/https://answers.unity.com/themes/thub/images/avi.jpg)