Avatars

An avatar is a representation of a physical object, like the ball, slingshots and flippers. In the P3, avatars are used to detect collisions with other GameObjects.

See the SDK documentation in file:///C:/P3/P3_SDK_V0.8/P3SampleApp/Documentation/html/_g_u_i_layer.html 

P3Playfield

The P3Playfield prefab is located in Assets\Resources\Prefabs\Framework\P3Playfield.prefab

It is instantiated in Setup (the base class of P3SASetup) with DontDestroyOnLoad flag, so it remains available in all scenes.

Here is the contents of the P3Playfield prefab with avatars shown. See the TechTip 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 volume from the last position to the new position is used to detect collisions with other GameObjects.

ExperimentalBallTracker tries to track up to 4 separate balls on the grid all at once. Based on the name, it’s not clear if the feature is complete or not.

FlipperLeftAvatar and FlipperRightAvatar represent the flippers. They track the up and down movement of the lower flippers.

The SlingshotLeftAvatar and SlingshotRightAvatar represent the slingshots. They track the movement of the slingshots when the coil triggers.

At runtime, there is an avatar trail object created for each avatar. The trail object is created by PlayfieldObjectProjection to initialize its Trail parameter. The avatar trail objects are visible in the Hierarchy at runtime when you look under DontDestroyOnLoad/P3Playfield(Clone)

P3Playfield has individual options to show: the ball path, gates, flippers, slingshots, the playfield overlay, and/or the infrared grid. I didn’t see any change when showing the ball path, gates or the playfield overlay. Showing the flippers or the slingshots displays the stylized outline of the avatars. Showing the IR grid shows the beams crisscrossing over the screen.

Collisions

To determine if your GameObject collides with the ball, create a RigidBody and a Collider in you 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 None if 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 HitBySlingshots(). This function returns the side of the slingshot or None if 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

}

Ball Decorations

The Home scene hierarchy contains a BallDecorators. This object tracks the ball and decorates it with a particle system. 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 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, GreenPof and Ignition. These are disabled by default. To change to a different decorator, disable Smoke (remove the checkmark next to the game object name in the Inspector), enable the chosen decorator, and edit Planar Ball Follower in BallDecorators to assign the chosen decorator to the Follower parameter.

New Playfield Overlay

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 when developing an app and you need to position something 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, just add the PF_OVERLAY_NEW prefab to your scene and make sure it is enabled.

Remember to disable or remove the overlay when you are done with it.