Raycast are not always updating in FixedUpdate
Hello, I've got a problem with raycasts. I know that they are a physic object and physics are always update in fixed update.
In my application I have a rubik's cube that can rotate all of its sides. After every rotation I want to know which faces are facing towards the camera. For this I'm using raycasts.
Unfortunately, in about 1 of 20 cases, the raycasts didn't update and the old faces are still being detected and this messes up my whole "game".
I have to use a coroutine because I also rely on WaitForEndOfFrame. Every time before I check for the front facing fields of the cube, I make WaitForFixedUpdate.
What I've already tried: - adding rigidbodys to each face (with IsKinematic set to true and CollisionDetection set to Continous Dynamic)
// Rotate one side of the rubik's cube
afterCube.MakeFastCubeRotation(currentRotation);
// Wait for fixed update to update the world faces
yield return waitForFixedUpdate;
// Saves all faces that are facing towards the camera now
afterCube.UpdateFrontFacingSquares();
I can't fix this problem. Does anyone of you know what I could do or what I may be doing wrong? The only thing that I can think of is that sometimes the cube rotates in fixed update and if it's already in fixed update, it doesn't wait for the next fixed update to check for the new faces but I don't know if that is possible.
(For info: only the cube rotates, the raycasts are always at the same position and are facing the same direction)
Your answer
Follow this Question
Related Questions
How to raycast object as far as possible, without collision? 0 Answers
unity 5 physics.raycast ignores mesh collider 1 Answer
Raycast collision vs unity collision system ( 2D Android game). 1 Answer
raycast gets wrong layer 2 Answers
RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) question 0 Answers