- Home /
Mouse Follow Problem
Hello, I'm using Unity Personal to develop a simple 2D game.
I made a Scene with just an Othographic Camera and one object with a single script to illustrate the problem:
void Update () {
Vector3 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = 0;
transform.position = target;
}
This script will make the object follow the mouse.
The "target.z = 0" part is because the camera is looking up the z axis and I want the object to stay on the z=0 plane.
Problem: moving the mouse fast enough results in an offset between it and the object.
My game is touch and I don't like the collider area getting away from the finger.
What is the cause? If the Update frequency is too low, is there a way I can increase it? If not, what can I do about it?
Thanks.
Answer by Cynikal · Aug 29, 2016 at 04:09 PM
Unfortunately, there will always be a slight delay.
You're moving the mouse. Unity then has to know where the mouse has moved to, then translate that info to the game object, then the renderer has to render the changes, etc. Point being, if you consider the mouse as Process 1, the actual display of moving the box would be like, Process 10. Now, considering that you're continually moving the mouse, it gets ramped up.
You said your game was a touch game. Cool. I understand you're using a mouse during testing. Computer mice use acceleration. Your finger on a phone...would not. Export it to a phone, then see if the issue is as bad as it is with the mouse.
There isn't a way to increase the update, as it's the "fastest" firing method. (Multiple times per frame)
@Cynikal I did the tests on a phone and the problem is even more noticeable. Probably because rendering is even slower there and it's quite confusing for the player.
I just made a test removing VSync and I hit 2200 FPS. Useless to say this is fast enough for the offset to disappear.
So I might post another questions on the disadvantages of disabling VSync or study a bit more first. But even now I guess that would put the phone under a lot of stress so it might not be a solution.
Thank you very much for your help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612091801im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Detect Collisions with Object following Mouse Movement 2 Answers
[2D] Problem With Mouse Follow Object 1 Answer
Mouse Follow (Not Working) - ): 1 Answer
Mouse Look/Follow is not following first person 0 Answers
Mouse follow collider in a 2D game 0 Answers