Greetings everyone, sorry for my english.
Currently trying to make 2D pong game for 4 players. Everything is okey beside one thing…
First of all i have made traditional a game for 2 players, so top and bottom walls were impermeable for ball. Then i have added paddle on top and bottom, as no wonder ball still baunced of top and bottom wall, so i need to make top and bottom permeable for ball. When i have maded all my paddles start to move out of the screen. Because nobody stoped them, however ball started to pierce all walls. Thx for reading till this line ![]()
The main question is, how does it possilbe to make all the walls permeable for ball and not permeable for paddles? Code for walls and game setup is bellow.
#pragma strict
function OnTriggerEnter2D (hitInfo : Collider2D) {
//Debug.Log(hitInfo.name);
if (hitInfo.name == “BALL”) {
var wallName = transform.name;
GameSetup.Score(wallName);
hitInfo.gameObject.SendMessage(“ResetBall”);
GetComponent.().Play();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\
#pragma strict
var theSkin : GUISkin;
var theBall : Transform;
function OnGUI () {
GUI.skin = theSkin;
if (GUI.Button (new Rect(Screen.width/2 - 121/2, 35, 121, 53), “Start again!”)) {
Debug.Log(“ТАДАМ!”);
playerScore01 = 0;
playerScore02 = 0;
theBall.SendMessage(“ResetBall”);
}
GUI.Label (new Rect(Screen.width/2 - 150, 20, 100, 100), “” + playerScore01);
GUI.Label (new Rect(Screen.width/2 + 150, 20, 100, 100), “” + playerScore02);
}
static var playerScore01 : int = 0;
static var playerScore02 : int = 0;
static function Score(wallName : String) {
if(wallName == “rightWall”){
playerScore01 += 1;
} else {
playerScore02 += 1;
}
//Debug.Log("Player Score 1 is " + playerScore01);
//Debug.Log("Player Score 2 is " + playerScore02);
}
var mainCam : Camera;
var topWall : BoxCollider2D;
var rightWall : BoxCollider2D;
var bottomWall : BoxCollider2D;
var leftWall : BoxCollider2D;
var Player01 : Transform;
var Player02 : Transform;
var Player03 : Transform;
var Player04 : Transform;
function wallsCollis() {
topWall.size = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width * 1.5f, 0f, 0f)).x, 1f);
topWall.offset = new Vector2(0f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height, 0f)).y + 0.5f);
rightWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height * 1.5f, 0f)).y);
rightWall.offset = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x + 0.5f, 0f);
bottomWall.size = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width * 1.5f, 0f, 0f)).x, 1f);
bottomWall.offset = new Vector2(0f, mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).y - 0.5f);
leftWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height * 1.5f, 0f)).y);
leftWall.offset = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).x - 0.5f, 0f);
Player01.position.x = mainCam.ScreenToWorldPoint(new Vector3(75f, 0f, 0f)).x;
Player02.position.x = mainCam.ScreenToWorldPoint(new Vector3(Screen.width - 75f, 0f, 0f)).x;
Player03.position.y = mainCam.ScreenToWorldPoint(new Vector3(0f, 60f, 0f)).y;
Player04.position.y = mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height -60f, 0f)).y;
}
function Start() {
wallsCollis();
}
function Update() {
wallsCollis();
}
Thank you in advance!