Hi. I want to know how to have a simple collision between the screen and my paddle. I am making a simple pong game. I dont want to use extra cube to put on each side of the screen. I mean just like in any other open source engine like xna.
It should be something like this
if(paddle.position.x > Screen.width){
// collision detected
}
Usually thats how it is made in xna because the origin is on the top left. In unity though im not sure. origin is on center now when i tried to track my x position compared to screen width its shows something like this
and this is my code
void Update () {
if(Input.GetKey(KeyCode.D)){
this.transform.Translate(new Vector2(2,0f) * Time.deltaTime);
Debug.Log("paddle position X: " + this.transform.position.x + ", Screen width: " + Screen.width / 2);
if(this.transform.position.x > Screen.width / 2){
}
}
}
I even divide it by 4 since it starts at center but still the width is far greater even though the paddle reach the end of the screen width.
I havent added the paddle width yet but it should be close enough.
So ah can someone help me about here? the most basic simple collision thing?