I’m making a pong game,and my ball and paddles keep going through the border.I have already tried the empty object trick,and I have also tried using the following code:
transform.position.y=Mathf.Clamp(transform.position.y,0, 100);
However, when using the above, my paddles no longer move =(
Are there any other ways to keep this from happening? Also,here is my current code for the player 1 (player 2 is the same, except for different key binders):
function Update () {
if(Input.GetKey(“up”)){
transform.Translate (0,4 * Time.deltaTime,0);
}
if(Input.GetKey(“down”)){
transform.Translate (0,4 * Time.deltaTime,0);
}
}
and the code for the ball mover logic:
function Start () {
rigidbody.freezeRotation = true;
yield WaitForSeconds (2);
rigidbody.AddForce (Random.Range(-4.1,4.1) , Random.Range(-4.1,4.1) ,0);
}
function Update () {
transform.position.z = 0;
}
Maybe there is something wrong with them? Please help!
FYI I am using this page for reference:
Thanks!
Kenzie