Paddle Moving With Mouse Issues

Hey,
I am working on Unity 2d Game dev Section 12/189 Block Breaker game, and I am trying to get my paddle to move with my mouse, but when I start my game, it moves the paddle to 30000+ position in the world, I do not know what could cause this, the only thing I changed from the original code is some of the variables, but they should not effect the game mechanics, someone please help, it would be much appreciated.
Problem2

Hi,

Welcome to our community! :slight_smile:

Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

And have you already tested the ScreenToWorldPoint method?

Thank you for replying, I tried making some print functions to show me the values of the variables, which has now made me even more confused, since the variables seem to be working fine, it is just the position that is having issues, I am printing the transform.position variable, which I am assuming should be the variable that actually manages the movement of the object, it works with the xmin and xmax, but it is not being represented on the object when I click play, I do not know why this is.
Problem3

What exactly did you log into your console? Those values look as if they were positions in the screen space.

That is the weird thing, I am printing the paddle pos into console, so it should be correlating the same way, but its not.
Problem5

I’ve just taken another look at one of your screenshots. Could it be that the Paddle is parented under a game object with a Canvas component? If so, that would explain the “weird” values.

Non-UI elements must not be parented to a game object with a Canvas component.

Privacy & Terms