Break-out clone game - how do I prevent paddle movement outside the play area
First of all, newbie alert.
I have been working on a simple break-out clone game to learn Unity. So far so good, but one issue I cannot resolve: how to prevent my movement object (paddle) going outside the playing area.
The paddle is mouse-controlled using the following in the FixedUpdate() method for my paddle object:
rigidbody.MovePosition(new Vector3(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, 0, 50)).x, -17, 0));
So to be honest, this is taken from a really good online tutorial, however it did not cover keeping the object within x-axis bounds.
The issue is the gameobject (purple paddle) moves through the side walls. I cannot seem to get a collision on the paddle or the wall itself. Both objects have a basic unmodified Box Collider defined, and I was hoping the collider would invoke and stop the paddle movement.
I have tried all sorts of solutions in the FixedUpdate() method, with all sorts of weird results :-) but I cannot manage to figure out the way to a workable solution.
Can anyone point me in the right direction?
It's a 2d game created in a 3d project.
Your answer
Follow this Question
Related Questions
getting maximum x and y values of mouse position 1 Answer
2D Platformer Character Acts Weird When Collide Side of a Platform 0 Answers
How to have units in a formation when moving/arriving at mouse location (RTS Style)? 0 Answers
Detecting missing collision in 2D platformer to change direction for enemy - without Raycast 1 Answer