2D: Sluggish/Restricted Movement

Hi,

I am trying to have my character sprite follow the mouse position on one axis, which works. However the amount that the character moves is very limited. Below is the code:

void moveLR (){
Vector2 mouse = Camera.main.ScreenToViewportPoint (Input.mousePosition);
transform.position = new Vector2 (mouse.x, transform.position.y);
}

I don’t understand why moving my character sprite is not following the X position of the mouse entirely. If I am not communicating what I mean very well, I can submit a demo of the game to show the problem in action.

Any help on intensifying movements in this code? I am more than happy to recreate the function from scratch in order to have the mouse follow the X Axis properly.

Thanks,
Kittik

You’re using ScreenToViewportPoint which translates the mouse position to the viewport. The viewport is only 1 unit wide and high so that wouldn’t translate very well to the screen width and height. You can either multiple the ‘mouse’ variable by your screen width and height or just use ‘ScreenToWorldPoint’ instead which should work.

That makes sense and it works perfectly now! Thank you very much. You’ve saved me quite a lot of time.