- Learn
- Tutorials
- Physics Labs
- Push Lab
- 2 Place the Carts
2 Place the Carts
Move either cart along its rail, let go without throwing it, and bring both carts home.
Drag either cart along its rail. Release it, then press Home or the orange Return button.
Open the downloaded file with File › Open Project... in Myth Engine.
2.1 The Idea
The carts have waited on the bench long enough. Put your pointer against Blue Cart and draw it along the upper rail. Copper stays below, with its load above it. Each cart keeps its own lane.
Before the workshop can compare pushes, you need room to arrange the experiment. This chapter lets you arrange it. The dial still waits.
A Logic Component gives an Object behavior through Events and Actions. An Event starts work when its named moment arrives, such as a mouse press. Its Actions do the work.
Holding a cart and leaving it alone need different responses. A Mode chooses the response. Think of the rail’s handle being engaged while you place the cart, then released when you let go. In Holding, your pointer places the cart; in Released, native physics owns its motion.
The change between them matters. Letting go should leave the cart where you placed it, without turning a quick drag into a throw. You are arranging the apparatus. The push comes next chapter.
A Function is a named piece of work that other Logic can call. Release Cart handles letting go. Return Cart Home will use that release before moving a cart back to the same starting place.
2.2 The Plan
Capture Cart Press remembers the grabbed cart and the place you touched. Place Cart on Rail holds it. Release Cart gives that body back to physics as soon as the drag ends.
Home reaches each cart through Return Carts. The orange button takes another route: Return Button Response sends returnCarts, and each cart returns itself. Both routes share a quiet click.
2.3 Set Up
Continue with the prepared workshop you made last chapter, keeping its Scene and Game Settings. The kit already supplies the button picture and sound listed below.
Make Return Carts in Game Settings > Input Manager, with Home as its binding. Build Return Button before placing it. Its setup row tells you where the new Object belongs in the Scene.
HomeThis is the first chapter with Logic. Turn on Settings > Advanced Mode so Execute Script is available in the Action list. Keep Making what a card shows beside you for Logic Components, Variables, Events, Modes and Functions. The Library and Script passages explain the supplied input helpers below.
Build the helpers first. Some cards name an attachment you will make later in this chapter, after its resource is ready.
2.4 Remember the Press
2.4.1 Cart Press Input
Grab the cart near its end, and that point should stay under your pointer. The cart should not jump to put its center there. The workshop remembers where your hand began.
Cart Press Input is a supplied Library for that small input job. Download its file from the card. Import that file into the Library resource and match its wiring so the following Scripts can find it.
The Library records selection and the grab offset, leaving every change in motion to your native Logic.
push-lab-cart-press-input.js1.8 KBcartPressCartPressInput2.4.2 Capture Cart Press
The cart needs its own listener before you press it. Capture Cart Press connects that cart to the Library, which remembers the exact press.
Make a Script with this name and place the supplied source in Script Code. Keep this source whole. Here, ctx and api connect the supplied helper to its calling Object. Movement stays in Logic.
// Capture the exact point that the hand grabbed.
lib.ext.cartPress.attach(ctx, api);Download this Script source2.4.3 Capture Control Press
The orange button needs to recognize its own press too. Capture Control Press uses the same Library without asking for a cart’s grab offset.
Make this as another Script. Its added false tells the helper to skip the drag offset. Both calls keep the same supplied connection names.
// Remember whether this control received the exact press.
lib.ext.cartPress.attach(ctx, api, false);Download this Script sourceNothing moves yet. The workshop can remember which cart you grabbed and where you touched it.
2.5 Let Go and Return
2.5.1 Release Cart
You let go. The cart stays still on the rail, even if your pointer was moving fast. Release Cart makes that handover deliberate.
Its cart Parameter identifies the body being released. The required Transform and Collider give the Function the pieces it needs. A held cart resumes from rest.
A cart already released keeps its existing motion, which will matter when next chapter gives it a push.
Returns a held cart to native physics without throwing it. Released carts keep their existing velocity.
StructuraltransformTransformcolliderCollidercart.collider.fixed == true- Applies to
cart- X Velocity
0- Y Velocity
0
- Applies to
cart- Spin
0
- Applies to
cart- Component Value
cart.collider.fixed- Value
false
2.5.2 Return Cart Home
Each cart needs a familiar place to begin another experiment. Return Cart Home ends a hold, stops the cart, and puts it back on its rail.
The same Function returns either cart, despite their separate rails. Returning leaves the mass alone.
Stops one cart and returns it to its chosen lane start without changing mass.
StructuraltransformTransformcolliderCollider- cart
cart
- Applies to
cart- X Velocity
0- Y Velocity
0
- Applies to
cart- X
homeX- Y
laneY
2.5.3 Play Workshop Click
Home and the orange button should sound like the same apparatus answering. Play Workshop Click gives both that quiet answer. Its silent reset and import cases prepare for later chapters; no extra control is missing here.
Plays the quiet workshop click for an accepted input request. Reset, setup import and canceled hands stay silent.
accepted == true- Sound
Workshop Click
The helpers are ready for their callers.
2.6 Give the Carts a Hand
2.6.1 Place Cart on Rail
Blue Cart can now follow your pointer. The press listener remembers which cart you touched and its grab offset, so the body stays beneath your hand.
Place Cart on Rail prepares the listener after the workshop opens, before you begin arranging the carts. Its short timer rings once. A selected press stops the cart, fixes its Collider in place, and chooses Holding for the held Event.
The Shared Variables describe the rail and home position. Per Instance Variables remember this cart’s current drag. Declare both kinds in the Logic editor, as Making what a card shows describes.
The Components row needs the existing cart Collider. Add its reference as collider in the Logic’s Components card. Keep the self. prefix shown on the generated card out of that Name field.
Before filling the first panel, prepare its later target. Create While the Left Mouse Button Is Held with Released and Holding as its Modes. Keep Released as its starting Mode. Their Actions can wait for the next panel. The first panel’s Switch Mode can now choose that Event and Holding.
Place one exact cart along its rail with the pointer, release it from rest, or return it home.
Any ObjectCollider- Timer Name
"cartInputReady"- Repeat Every (s)
0.02- Ring Once
Yes
- Script
Capture Cart Press
self.pressSelected == true- X Velocity
0- Y Velocity
0
- Component Value
self.collider.fixed- Value
true
- Event
While the Left Mouse Button Is Held- Mode
Holding
Now follow the held Event. It has two Modes, Released and Holding, within one Event. Released starts with no Actions to carry out. Holding subtracts the grab offset before placing the cart, keeping the original contact point under your pointer.
The clamp expression keeps the requested position between the rail’s limits. The lane height stays fixed. Drag diagonally and the cart still travels along its rail.
Enter these expressions as shown, including their prefixes. In the handX expression, valueMember(event.position,“x”) takes the pointer Event’s horizontal coordinate. The subtraction removes this hand’s grabOffset. Here, self reads this cart’s Per Instance value; @self reads its Shared value.
- Variable
handX- Value
valueMember(event.position,"x") - self.grabOffset
- X
clamp(self.handX, @self.leftLimit, @self.rightLimit)- Y
@self.laneY
Releasing the button gives the cart back to physics, even when the pointer has moved outside it. Interruptions end the hold too. Losing focus or canceling a touch should leave the bench usable when you return.
These interruptions repeat the same release and Mode change. After attaching this Logic to both carts, you can try the first drag. The load:succeeded Event is preparation for the saved experiments you will build in a later chapter. Myth sends it after restoring an experiment. That Event releases an interrupted hold and starts listening on the restored cart. The cart can respond again.
- cart
self
- Event
While the Left Mouse Button Is Held- Mode
Released
- cart
self
- Event
While the Left Mouse Button Is Held- Mode
Released
- cart
self
- Event
While the Left Mouse Button Is Held- Mode
Released
- cart
self
- Event
While the Left Mouse Button Is Held- Mode
Released
- Script
Capture Cart Press
Finally, the cart listens for the keyboard Command, Return Carts. The returnCarts Custom Event comes from the orange button you will build below.
Both use this cart’s lane values. Both finish in Released, ready for another press.
- cart
self- homeX
@self.homeX- laneY
@self.laneY
- Event
While the Left Mouse Button Is Held- Mode
Released
- cart
self- homeX
@self.homeX- laneY
@self.laneY
- Event
While the Left Mouse Button Is Held- Mode
Released
The same Logic serves both carts, with each Object supplying the height of its own lane.
2.7 Connect the Two Lanes
2.7.1 Blue Cart
Attach Place Cart on Rail to Blue Cart. Attaching it supplies the Shared Variable rows on the body you already built. Select this attachment in the Object’s Logic workspace to compare their values.
The lane height belongs to this cart’s center. Keep the limits and home position with the cart too; the Logic reads them when it needs them.
X 3.6, Y 0.93Blue Cart ArtX 3.6, Y 0.9X 3.6, Y 0.9ColliderNumberConstant6.75NumberConstant10.975NumberConstant5.975NumberConstant20.8752.7.2 Copper Cart
Copper uses the same behavior on the lower rail. Its laneY differs, so the lower cart stays below Blue instead of climbing into its lane.
Open Copper Cart in its Components workspace, with the Object itself selected. Under Properties > Variables, find laneY in Shared Variables and enter 8.2 in Value, keeping Kind as Constant. Leave Blue Cart’s laneY at 10.975. These are each Object’s values, with no extra Variable to create.
Keep the load Sprites already attached to Copper Cart, so they follow when the Object changes position. The load travels with its cart.
X 3.6, Y 0.9103Copper Cart ArtX 3.6, Y 0.9X 3.6, Y 0.9ColliderRear LoadWorkshop weight-26.04X -1.125, Y 0.825X 0.625, Y 0.95Middle LoadWorkshop weight-26.05X -0.375, Y 0.825X 0.625, Y 0.95Front LoadWorkshop weight-56.08X 0.375, Y 0.9X 0.75, Y 1.1NumberConstant6.75NumberConstant8.2NumberConstant5.975NumberConstant20.875Run Lab now. Drag each cart and let go, then use Home to bring them back. The orange button is next.
2.9 Play It!
Predict what will happen when you drag a cart diagonally and release it. Run Lab and compare.
- Grab Blue Cart away from its center and drag it along the rail. That contact point stays beneath your pointer.
- Drag up or down as well as sideways. Blue stays on its upper rail; Copper stays on its lower rail.
- Drag beyond either rail end and watch the cart stop at its allowed limit.
- Release after a quick drag. The cart rests where you left it, without a throw.
- Move both carts away from home, then press Home to return them to their starting places.
- Move them again. Press the orange Return button and both come home with a quiet click.
- Press empty space. Neither cart returns. The dial and Space still supply no push in this chapter.
2.10 How It Works
The press chooses a cart. Holding places it. Release hands motion back to physics, and Return restores its starting place.
The hand and physics take turns owning movement. They never need to pull against one another. You can use that same handover for arranging a body before another experiment begins.
2.11 If It Didn’t Work
A cart follows without a press? Look for the starting Mode on the held Event in Place Cart on Rail. Released starts empty; Holding carries the placement Actions. Restore that arrangement and the cart waits for your hand again.
Copper jumps onto Blue’s rail? Compare Copper Cart’s laneY with the lower lane value on its Copper Cart Object card. Give Copper its lower lane value. Run again, keeping the shared Logic as it is, and the carts should stay apart.
Neither cart takes a press? Open the Cart Press Input Library and check its Enabled switch is on. Compare Advanced Wiring and Load Order with the Library card. Compare Capture Cart Press next. The Script connects the listener; Place Cart on Rail still owns movement.
Home works but the orange button stays silent? Look for Return Button in Lab, then check both its Logic attachments. Listen for Control Press supplies the selection that Return Button Response needs.
A cart stays held after release? Look at Mouse Release in Place Cart on Rail. It needs Release Cart and the change back to Released. Restore those together and try dragging again, watching for the cart to stop when you let go.
2.12 Challenge
Choose a different home position for one cart, inside its existing limits. Move it away. Return should bring it to the home position you chose on that cart. Keep the other cart’s home unchanged, then restore the card’s value before continuing.
You can arrange both carts now. Next, the workshop gives them a push.
