← Yop2D

How to move a character?

Beginner guide · no code

Français · English · Español · Deutsch · Italiano · Português · Русский · 中文 · 日本語

In Yop2D, there are three simple ways to move a character, without writing code. Pick the one that fits your game.

Method 1: with on-screen buttons (left / right)

Great for a platform game, or a game where the character moves along a line.

  1. In your scene, add your character (a Square or an Image) and name it player.
  2. Add two objects to use as buttons, for example two Button objects (or two squares) named btnLeft and btnRight. Put them at the bottom of the screen.
  3. Open the scene's Blueprint.
  4. Add the “Object Held Down” event and choose btnLeft as its target.
  5. Add a “Push object” node: target player, Add X = -5, Add Y = 0.
  6. Link the event's output to the input of “Push object”.
  7. Do the same for btnRight, with Add X = 5.
  8. Save, then start the game: as long as your finger stays on a button, the character moves.
Object Held Downtarget: btnLeft
→
Push objecttarget: player · Add X = -5
👉 “Object Held Down” repeats on every frame while the finger stays on the button: that is why the character keeps moving. To go faster, raise the value (for example 8 or 10).

Method 2: with a virtual joystick

Great for a top-down game, where the character moves in every direction. No node needed.

  1. Add a Joystick object to your scene (category Interactives) and put it at the bottom left.
  2. Select the joystick. In the inspector, section “Joystick Control”, tap the “Object to move” button and choose your character.
  3. Save, then start the game: the character follows the joystick.
👉 Shortcut: if you give your character the tag Player (or Joueur), the joystick moves it automatically, even if nothing is chosen in “Object to move”. Careful: this tag wins over the inspector's choice.
👉 Going further: the formulas joystick.x and joystick.y give the direction (between -1 and 1). You can use them in a “Push object” node linked to “Every frame”, for example =joystick.x * 5. The “If joystick” node also has Up, Down, Left, Right and Idle outputs.

Method 3: drag it with your finger

Great for a puzzle, a card game or any game where you move pieces around.

  1. Select your object in the scene editor.
  2. In the inspector, tap ⚙ Object behavior and choose Dragged with a finger.
  3. Start the game: you can drag the object with your finger.
👉 To react when the player lets go of the object (for example to check it is in the right place), use the “Drag End” event.
👉 To allow or block dragging during the game (a puzzle piece in the right place, for example), use the “Change the behavior” node.

Tips