- Home /
Linerenderer: How to sample positions more frequently?
I am working on a project which consists of drawing a line, BUT, the most important thing is that I need to get the Y position on every X position. So, for every X I need a Y. Drawing a line and getting the positions works fine while I draw slowly. But when I move the cursor faster, even if the line gets drawn, the positions are not saved for every X, and this is a problem. You can just take a look at the image below. As you can see, the green line is the one that Unity provides, LineRenderer. Just to prove my problem, I have drawn a circle at every position saved on the Line. So, even though the line gets drawn, I can't save my positions. Is there a way to solve this? Thank you and have a great day!
You likely won't be able to sample any faster than the framerate you are running at, so the only way to sample fast would be to increase your framerate (note that this will be faster once you build your project). You still won't be able to sample every position though... you may be able to somehow sample the mouse position faster using another thread or even some other application running separately from unity but I don't know how you would go about doing that exactly. Why do you need every x position? Why can't you interpolate between the sampled positions to give an approximate y value for every x position?
Answer by LHAppri · Jul 13, 2020 at 05:32 PM
How are you saving the positions? Graphics & interacting with the Unity objects is always time-consuming. If you constantly save the mouse positions as fast as possible, and then separately use that information to draw the line you should be able to get more positions, although your line drawing may "lag" behind the mouse a bit.
You are still unlikely to get all of the mouse positions though and so will have to interpolate the coordinates between them.
After lots of changes around your solution seems to be the only way. But I don't get it, why is the line being drawn no matter how fast the cursor moves but the positions are saved so rarely. I don't do anything while drawing, only adding the positions to a list...