Skip to content
On this page

walls

At this point the game is almost playable. We just need to ensure that the puck going out of bounds resets the game.

Setup

  1. Duplicate any of the wall.

  2. Remove the mesh component from this wall gameObject so that there is no visible mesh, We only need the collider.

  3. Position and scale it so that it is behind any of the paddle. wall

  4. On the collider component of this wall gameObject, enable Sensor and enable-COLLISION_EVENTS. sensor

Making the collider a sensor ensures that the collider does not actually create reaction forces and enabling the COLLISION_EVENTS allows us to listen for these events.

Logic

Add the logic to <projectDir>/src/scripts/wall.ts

TypeScript
// fired because of the collider component
export const collisionEvent = (game, gameObject, {props}, c1, c2, entering) => {
    if(!entering)return;
    game.currentGameObject.children.puck.components.rigidBody.setTranslation({x: 0, y: 8, z:0}, true);
}

Add this script to the wall gameObject and duplicate this gameObject for the other paddle.

At this point the game should be playable.

Challenge

Setup a way to track score.

TIP

Refer to completed project thejsngin/pong3d. If you want a hint.