sample input more fequently than per frame

ok, i started out with unity and this is my first post here.

it seems to me that the Input.mousePosition is updated once per frame. i assume that the same is true for the touch input.
is there a way to get the position (mouse ant touch) more often then that?

Nope. Not that I’m aware of. Every time the update loop is called, it’s done one cycle of stuffs. Input, Update, physics, gui, all the onEvent type of functions, and just loops through those. I know there are more, and those are probably in the wrong order, but my point is, all the game loop is, is a bunch of functions being called in series over and over again. Input happens to be one of those functions that gets called in that loop. So even if you were able to call the Input.GetWhatever() call more then once per frame, the data is still only updated once per frame, and I doubt there is a way to force it to run an update as well.

thanks. that’s what i figured.
but would it be possible to do this with a .net plugin? has anyone tried that yet?

You certainly could fire up a thread and poll the mouse at a faster interval with some native code, but can I ask why you’d want to? It seems like the kind of thing where you are opening up a huge bag of worms for what is almost certainly an over-engineered solution. If you give us a little guidance in terms of what you want to do with the mouse position more frequently than once a frame, we can probably help you find a more reasonable solution that doesn’t require a separate thread and native code.

thanks.
my goal is to draw a line based on mouse/touch input. i make this by sampling the input once a frame and draw a line segment.
this works fine as long as the input movement isn’t too fast. but fast curved moves produce edgy lines. i know about catmull-rom spline and bezier, but i would like the line to be as close to the actual movement as possible. so is there a better solution than a plugin?

Perhaps just uncap the frame rate and make use of Time.deltaTime to keep rendering speed in check.

could it be that the mousePosition updates even slower than the unitys update? i’m asking because even when running without vsync on windows at 800fps the line is still edgy wehen drawn fast.

So, just like in any drawing program ever. Seems like alot of work

One of the old Visual Basic beginner examples I remember doing was a line drawing application that used the previous mouse position and connected a line to the current mouse position each update cycle.

oh, ok. so this is a common issue?
i have tried photoshop and fast drawing in photoshop produces lines with much better resolution. so i thought the edges might be unity specific.
but now i tried windows paint, and you are right hpjohn, the line in paint looks just like the one i draw in unity.
what is actually the problem here, the os resolution? and are ther any approaches to it other than smoothing?

Yea, it’s a common issue - most mice poll around 125 times a second by default, so no matter what approach you take you won’t get more samples than that. Getting a smooth accurate curve based on that polling (and realistically you’re looking at less than that) is a very specific problem with a lot of approaches to solving; lucky for you, specific conceptual problems are far easier to find information on than broad issues or Unity specific issues.

I’d suggest taking the conversation somewhere like Stack Overflow and asking it in the highest level sense you can. Frame the conversation around exactly what you are trying to do and I’m sure the SO community will give you some great directions to look into. Assuming your end algorithm works well, there will be little difference between 30 and 125 samples a second visually.

Just be sure to mention that you don’t just want to smooth between each data point; you want to reconstruct/guesstimate the actual path as accurately as possible.

P.S. I love that guesstimate is a valid word in Firefox :smile: