An avatar is a representation of a physical object, such as a ball, a slingshot, or a flipper. In a P3 application, avatars are used to detect collisions with other GameObjects.
The P3Playfield prefab is in Assets\Resources\Prefabs\Framework\P3Playfield.prefab
It is instantiated in Setup (the base class of P3SASetup) with the DontDestroyOnLoad flag, so it remains available in all scenes.
Here are the contents of the P3Playfield prefab with avatars shown. See the tech tip on Virtual Targets for more information on the other children of P3Playfield.
The MouseBall synthesizes grid events to emulate the ball position when the mouse button is down. This is used to move the ball to test the app in the Unity simulator.
BallAvatar represents the ball's most recent position. It gets the position and velocity from P3Controller. The swept volume between the previous and current positions is used to detect collisions with other GameObjects.
ExperimentalBallTracker was an attempt to track up to four separate balls on the grid simultaneously. This feature is not functional.
FlipperLeftAvatar and FlipperRightAvatar represent the flippers. They track the up and down movement of the lower flippers.
SlingshotLeftAvatar and SlingshotRightAvatar represent the slingshots. They track the movement of the slingshots when their coils are triggered.
At runtime, an avatar trail object is created for each avatar. PlayfieldObjectProjection creates the trail object and uses it to initialize its Trail parameter. The avatar trail objects are visible at runtime when you look under DontDestroyOnLoad/P3Playfield(Clone) in the Hierarchy.
P3Playfield has individual options to show: the ball path, gates, flippers, slingshots, the playfield overlay, and/or the infrared grid. Enabling the ball path, gates, or playfield overlay options currently produces no visible changes. Showing the flippers or the slingshots displays the stylized outline of the avatars. Showing the IR grid displays the beams crisscrossing the screen.
To determine if your GameObject collides with the ball, add a Rigidbody and a Collider to your object, and in the OnTriggerEnter() method, call HitByBall().
public class MyHittableObject: P3Aware { public void OnTriggerEnter(Collider other) { if (HitByBall(other)) { PostGUIEventToModes("Evt_ObjectHit", position); // Let the mode layer know about the collision // Add more GUI layer reaction code here } } } |
To determine if your GameObject collides with the flippers, call HitByFlipper(). This function returns the motion of the flipper during the collision or FlipperHitType.None if there is no collision.
using Multimorphic.P3App.GUI; public class MyHittableObject: P3Aware { public void OnTriggerEnter(Collider other) {
FlipperHitType hitType = HitByFlipper(other); if (hitType != FlipperHitType.None) { PostGUIEventToModes("Evt_ObjectHit", position); // Let the mode layer know about the collision // Add more GUI layer reaction code here } } } |
public enum FlipperHitType { None, Idle, Upward, Downward } |
To determine if your GameObject collides with the slingshots, call HitBySlingshot(). This function returns the side of the slingshot or SlingshotHitType.None if there is no collision.
using Multimorphic.P3App.GUI; public class MyHittableObject: P3Aware { public void OnTriggerEnter(Collider other) {
SlingshotHitType hitType = HitBySlingshot(other); if (hitType != SlingshotHitType.None) { PostGUIEventToModes("Evt_ObjectHit", position); // Let the mode layer know about the collision // Add more GUI layer reaction code here } } } |
public enum SlingshotHitType { None, Left, Right } |
The Home scene hierarchy contains BallDecorators. This object tracks the ball and applies a particle effect to it. By default, this is a smoke effect.
If you run P3SampleApp on the real P3 machine, you will see the smoke effect following the ball. If you run the app within the simulator, the effect does not work. PlanarBallFollower is not compatible with MouseBall because it thinks the ball is not on the grid.
There are also sample particle systems for: Fire, Inkblot, GreenPoof and Ignition. These are disabled by default. To change to a different decorator, disable Smoke (clear the checkbox next to the GameObject name in the Inspector), enable the chosen decorator, and edit Planar Ball Follower in BallDecorators to assign the chosen decorator to the Follower parameter.
The PF_OVERLAY_NEW prefab is located in Assets/Resources/Prefabs/GUI/PF_OVERLAY_NEW.prefab. It contains a detailed image of the physical playfield.
The Home scene in P3SampleApp contains a copy of the PF_OVERLAY_NEW prefab. The overlay is disabled by default. To enable it, select PF_OVERLAY_NEW in the Home scene hierarchy, then click the checkbox next to the name PF_OVERLAY_NEW in the Inspector.
This playfield overlay is convenient during development when positioning elements on the screen relative to the side targets, slingshots, lower flippers and/or apron. If you are working on a different scene and you need the overlay, add the PF_OVERLAY_NEW prefab to your scene and ensure it is enabled so it will be displayed.
Remember to disable or remove the overlay when you are done with it.