Skip to content

Pinball Experiment

matthewi98 edited this page Jul 26, 2022 · 5 revisions

Documentation WIP

Description of how it works

The user either pulls back a spring or drags in a direction in order to launch a ball towards a target.

Setup:

  • GameObject.Find's all necessary gameobjects in task prefab, excluding those already found in BilliadsTask.
  • Enables the obstacle according to the JSON.
  • Sets the tilt if per_block_tilt_after_fire is false.
  • Sets timer time based on JSON.
  • Sets the surface materials based on JSON, using SetSurfaceMaterial in BaseTask.

Step 0:

The user clicks, and drags their mouse in the opposite direction that they want the ball to go.

  • Detects user click, then:
  • Starts the timer. If Spring mode:
  • Draws the direction indicator or arc.
  • Calculates the direction.
  • Fires pinball once the mouse button is lifted. If Flick mode:
  • Sets flick start time.
  • Flicks pinball once the mouse button is lifted.

FirePinball():

  • Stops timer.
  • Sets the tilt if per_block_tilt_after_fire is true.
  • Calculates pertubation if per_block_type is rotated.
  • Sets pinball velocity based on direction and force.
  • Plays hit sound.
  • Calculates pinballAlignedTargetPosition.
  • Starts tracking pinball using AddTrackedObject.
  • Increments step.

FlickPinball():

  • Calculates the direction.
  • Calls FirePinball().

Step 1:

The pinball is travelling towards where the user launched it.

  • If per_block_show_path is true in the JSON, tracks points for the LineRenderer.
  • Calculates distanceToTarget based on the distance from the ball to the 'pinballAlignedTargetPosition`.
  • Tracks the closest position the ball has been to the target in lastPositionInTarget.
  • Updates score if pinball is within 20cm of the target. Score is calculated using the distance to the target.
  • Overwrites score only if its greater than the current score.
  • Increments step if ball travels away from the target for more than 500ms.
  • Increments step if ball collides with target.
  • Increments step if ball collides with obstacle.
  • Increments step if MAX_TRIAL_TIME is exceeded.
  • Increments step if ball travels away from target after entering target. enteredTarget is set to true if the ball is within 5cm of the target.
  • Increments step if ball stops moving.
  • Increments step if ball exceeds cutoff distance.

Step 2:

Ball trail is shown, final score is calculated,

  • Pauses the screen for 1.5s.
  • Stops the ball from moving.
  • Sets ball position to lastPositionInTarget.
  • Shows ball trail based on per_block_show_path. Green if hit the target, yellow if within 5cm of target, white if else.
  • Plays particles if the ball lands within 5cm of target and the user didn't run out of time when firing.
  • Starts bonus text animation.
  • Sets bonus text to green if ball hit target. Red if didn't get any score. White if got at least 1 score.
  • Plays incorrect or correct sound effect depending on if the ball got within 5cm of target.
  • Increments step.

List of JSON parameters

Key Value Description
exp_record_score Boolean Whether the "score" of the task is logged to result
per_block_type "instruction" or "aligned" or "rotated"
per_block_rotation Float Perturbation angle
per_block_targetListToUse List of floats Angle in degrees of target (90 is forward)
per_block_show_path Boolean Whether to show the path the pinball took after the ball stops
per_block_tilt_after_fire Boolean Whether tilt is shown before or after firing
per_block_list_camera_tilt List of floats Tilt angle in degrees of camera, back wall, bonus text
per_block_list_surface_tilt List of floats Tilt angle in degrees of physics surface
per_block_obstacle Boolean Whether an obstacle is placed halfway between the ball and the target. If user hits the obstacle, the trial ends.
per_block_instruction Instruction text
per_block_surface_materials
per_block_track_score Boolean Whether this is a practice round
per_block_timerTime Float Time in seconds user has to fire pinball in order to receive points

instruction: Replaces trial with instruction trial that uses per_block_instruction.

aligned: Perturbation is disabled.

rotated: Perturbation is enabled. Initial ball direction is influenced by per_block_rotation.

List of Optional JSON parameters

Key Value Description
per_trial_dynamic_tilt With dynamic tilt, the surface tilts from flat to surface_tilt depending on the ball's distance to the target.
per_block_dynamic_tilt_curve "sin" or "cos" or "linear" Determines how the surface should map the ball-target distance to a tilt.

As the ball gets closer to the target:

sin: The surface goes from flat, to surface_tilt, to -surface_tilt, to flat, along a sine curve.

cos: The surface goes from flat, to surface_tilt, to flat, along a curve.

linear: The surface goes from flat, to surface_tilt.

Tracked Parameters

-Pinball position

Logged Parameters

-Direction Indicator Position

-Last Position In Target (the closest position the pinball has ever been to the target)

-Home Position

-Target Position

-Distance between pinball and target

-Indicator Angle

-Spring Pull Distance

-per_block_show_path

-per_block_tilt_after_fire

-error size

-surface tilt (when dynamic)

-aligned pinball position (when dynamic)