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
Duplicate any of the wall.
Remove the mesh component from this wall gameObject so that there is no visible mesh, We only need the collider.
Position and scale it so that it is behind any of the paddle.
On the collider component of this wall gameObject, enable
Sensor
andenable-COLLISION_EVENTS
.
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
// 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.