- Home /
Raycast not registering hits when mouse is moving fast.
Hello all. I am trying to paint a 3D model vertices using a raycast from the camera (when the mouse is down) .
However, when I move the mouse really fast, the raycast is not detecting any hits on the model, and it leaves some big spots when painting. Everything is fine when the mouse is moved slowly.
What could be a solution to this issue?
Missing spots:
Drawing that is fine:
Answer by CodesCove · Mar 13, 2021 at 02:56 PM
I think that if you move mouse fast enough you will not get continuous line of mouse positions. Trying to Raycast more often will not help because it's not affecting the mouse position in any way. If you are trying to use couroutine to somehow increase the resolution you cannot exceed frame rate (of course you can iterate inside the coroutine in that frame, but this will not help either).
What you need to do is to interpolate the missing positions between the actual mouse positions and do the raycast for them retrospectively (for example spline interpolation for smooth lines curves)
That could actually work, I was thinking of interpolating the vertices on the mesh but I hit a big performance issue, but your suggestion makes a lot more sense.
Answer by ARobbins67 · Mar 12, 2021 at 10:09 PM
Hi, I'd say that the raycast is detecting all the hits when it is called, but the mouse is probably just moving so fast that the raycast isn't sending out rays often enough for it to create the continuous line on the mesh that you're looking for.
There's multiple ways to solve this, but one way could be to create a Coroutine that calls the raycaster after a certain time step. You can then adjust that time step until it is small enough to create a continuous line with quick mouse movement. Hope this helps!