I have a sprite in a 2D mobile game I am making. And the sprite will be controlled by touching and dragging it on the mobile phone screen. But the problem is, the sprite will need to be moved very fast in the game by touching and dragging, and when I try to do it with the below code, there is a delay when it is moved very fast. It should always be where the finger is touched on the screen, so it has to be immediate and highly responsive to the dragging, it should always be where the finger is currently touching on the screen even at very very high speeds.
There’s no rendering delay so it’ll be your code or the input-stream from the device. The sprite is rendered at the Transform position, there is nothing else it knows about. Likely this is simply the resolution of the touch input coming in and nothing at all to do with rendering.
You could easily verify this by simply modifying the Transform position in script without using the input system. It changes instantly.
Also note, you cannot modify a Rigidbody2D/Collider2D by modifying the Transform. You modify the Rigidbody2D by using its API so don’t expect to modify a Transform and it to be a physics-based movement. Absolutely nothing else beyond the Transform itself changes when you modify it.
Physics (by default) only updates during the FixedUpdate but you can change that to per-frame with all the consequences of that. Even if you do that though, you’d modify the Rigidbody2D, not the Transform.
Physics-based dragging can be done using the TargetJoint2D which has arguments to control how strong/fast the movement is. You can see this done here: https://youtu.be/4NSKN3L0fvE?si=2giXnTzyO9uQs-sU
I know the behavior, I have no solution, from what I’ve understood there is a delay between the information of where the touch had happened, the mobile operating system informing the app and the rendering of your sprite. even a few milliseconds and it will remain behind. you can see this happening directly in the operating system, for example if you have android, exit all apps so you are on the device screen. chose one of the icons on the device main screen. touch it with the finger and move it around fast. it will lag behind.
you probably cant remove the touch input delay, try fruit ninja if its “blade” also has some delay, then it is probably impossible to properly fix (hardware side issue). i have a code which just snaps transform to “cursor”, works perfect on mouse and on Android there is delay happening, though it feels like it happens only with sprite, it hits target earlier than the melee weapon sprite moves (but that is probably human brain lag there also and the sprite isn’t just a dot of pixel)
Edit:
But maybe you can make a prediction system, based on previous movement, like the CS2 does in its netcode, lol, or something
(btw its junior assumptions, maybe there are easier ways)