When I run the Block Breaker game, I the mouse position does not match my paddle (like it does in the video). The paddle starts centered, but after the first frame, it jumps well to the right of my mouse position. It will move left or right as I move the mouse, but the mouse has to move far off the game screen just to center the paddle.
I’ve searched this on the forums and found other people talking about it, but could not fix it.
Tried: Building and running in browser, testing in program.
Version: 5.4.3
Attached is the screenshot of paddle script and object settings.
Thank you!
SOLUTION
I wanted to see what the mouse position number was. So I used this little line of code:
float mouse = (Input.mousePosition.x); print (mouse);
From this, I learned that the mouse position was based on an X Y axis that started its positive numbers at the bottom left of the play screen. So, a centered mouse value was at 400.
I could not find any way to adjust the X,Y axis for Unity, so I just went with it.
If the screen is 16 world units wide, then 8 is the center. Adding - 8 to this line of code, did the trick:
float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16 - 8;
This was also a reason that the paddle would not be constrained to the screed.
If our paddle is one world unit wide, then the max left and right would be -7.5 and 7.5.
I likely screwed up something in the setup process, but I’m glad that I did because it really forced me to dig in and find a fix.
Below is a screen of the code.