Drag and drop with triggers: drag the key onto the lock, and a collision game
Build a free-form drag and drop with Storyline's drag triggers: highlight the lock when the key is dragged over it, open it on drop only if the learner found the code (Otherwise: show a hint). Then a small collision game with "objects intersect" and a motion path.
Last updated 7 min read
How do I build a custom drag and drop, or detect when two objects touch, without Storyline?
Step by step
Add the pieces
Add a Drag Item named Key and a Drop Zone named Lock. Add a button "Read the note" that sets a boolean variable
KnowsCodeto true.Highlight on drag over
On the Key, add a trigger When dragged over → Lock → Change object state of Lock to Hover.
Open the lock on drop
Add a second trigger When dropped on → Lock, Only if
KnowsCodeis true, Then show layer "Unlocked", Otherwise show layer "Find the code first".Try it
Preview. Drop the key before reading the note: the hint shows. Read the note, drop it again: the lock opens.
What you'll build
Part one: a key the learner drags onto a lock. The lock lights up while the key is over it. On drop it opens, but only if the learner has read the note with the code. Otherwise a hint shows.
Part two: a tiny collision game. A ball moves along a motion path, the learner drags a paddle into its way, and "objects intersect" scores a point.
Part one: set up the slide
- Click Variables → Add Variable:
KnowsCode, boolean, false. - Pick Drag Item on the toolbar and click the slide. In Style, set its Name and Label to "Key".
- Pick Drop Zone and click the slide. Set its Name and Label to "Lock".
- Select the Lock, open States, and check it has a Hover state. Give Hover a bright border.
- Add a Button, "Read the note", with a trigger When user clicks → Set variable
KnowsCode=true. - Add two layers, both Starts hidden: "Unlocked" ("The door opens.") and "Find the code first" ("It's locked. Read the note.").
Drag items work without a mouse too: a learner can select the key, then select the lock. Your triggers fire either way.
Highlight the lock while the key is over it
Select the Key and add a trigger. Open it.
- When: type "drag" and pick When dragged over.
- Dragged over: pick Lock. Click the target icon and then the Lock on the slide, or choose it from the list. Leave it on Any drop zone to react to every zone.
- Then: Change object state, Lock, Hover.
It fires once each time the key enters the lock, not on every pixel of movement.
Open the lock on drop, Otherwise show a hint
Add a second trigger to the Key.
- When: When dropped on. Drop zone: Lock.
- Only if: Variable
KnowsCodeis true. - Then: Show layer "Unlocked".
- Otherwise: Show layer "Find the code first".
The sentence reads When dropped on Lock → show layer Unlocked · if KnowsCode is true, otherwise → show layer Find the code first.
Tip: When user starts dragging is there too, for a "pick up" sound or to hide the instructions as soon as the learner grabs something.
Try it
Click Preview.
- Drag the key over the lock: it lights up.
- Drop it there before reading the note: "Find the code first" shows.
- Click Read the note, then drop the key again: "Unlocked" shows.
Grade it as a question
Triggers are one way to answer a drop. To have it marked and scored instead, select the drop zone: under Answer, click the items that belong there. Type what the learner is told when it's right and when it's wrong, and what it is worth.
A graded drop zone counts like any question: what the learner places in it is marked right or wrong, adds to the score, and is reported to your LMS. Moving the item out or swapping it changes the answer. With no items picked, a zone stays free-form and unscored.
Part two: a collision game with objects intersect
- Add a circle Shape called "Ball" near the left edge.
- With the ball selected, click Add Motion Path on the toolbar. Click points across the slide to draw the path, set the duration, and save. Scenes adds a trigger that plays the path when the timeline starts, as Storyline does.
- Add a Drag Item called "Paddle".
- Make a number variable
Hits, starting at 0. - On the Paddle, add a trigger: When it touches another object → Touches: Ball → Adjust variable
Hits, Add (+), 1. - Add a text box that shows the score. See Variables, operators and formulas for showing a variable in text.
Storyline calls the event "object intersects". It fires when the two boxes first meet, and When it stops touching fires when they part. Objects that start the slide already overlapping don't fire until they part and meet again.
When a motion path completes
When a motion path completes fires when an object arrives at the end of its path. Use it to show a "Missed!" layer, or to send the ball back with Move along motion path again.
Move along motion path is the action that plays a path. Use it on a click instead of the timeline start if the learner should launch the ball.
Part of the documentation: Build.
Found something here that does not match what the product does? That is a bug in the guide — see all guides or tell us from the Help Center.