void FixedUpdate()
{
int layerMask = 1 << 8;
RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
{
if (!raycastSucceed)
Debug.Log("Did Hit");
raycastSucceed = true;
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.red);
RotateGameObject(hit.transform.position, objToRotateLookAT);
if(Vector3.Distance(transform.position, hit.transform.position) <= distanceToInteract)
{
anim.SetBool("Pickup Item", true);
}
originalRotFlag = false;
}
else
{
if (raycastSucceed)
Debug.Log("Did not Hit");
raycastSucceed = false;
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.yellow);
if (objToRotateLookAT.rotation != originalRotation && originalRotFlag == false)
{
objToRotateLookAT.rotation = Quaternion.Lerp(objToRotateLookAT.rotation, originalRotation, originalLookSpeed * Time.deltaTime);
}
else
{
originalRotFlag = true;
}
}
}
At this part it’s never getting to the else an the flag is all the time false so it keep rotating it to the original rotation. but I want it to rotate to the original rotation once and when it’s getting to the original rotation then set the flag to true.
if (objToRotateLookAT.rotation != originalRotation && originalRotFlag == false)
{
objToRotateLookAT.rotation = Quaternion.Lerp(objToRotateLookAT.rotation, originalRotation, originalLookSpeed * Time.deltaTime);
}
else
{
originalRotFlag = true;
}