mvbg

VM_CAMERA_MOVE_TO

VM_CAMERA_MOVE_TO is a GBVM instruction used to smoothly move the game camera to a new X and Y coordinate over time.

Purpose: Camera movement is crucial for guiding the player’s attention, revealing new areas, or creating cinematic effects. Unlike VM_CAMERA_SET_POS which instantly teleports the camera, VM_CAMERA_MOVE_TO provides a gradual transition. This is essential for:

When VM_CAMERA_MOVE_TO is called, the camera will begin moving towards the specified X and Y coordinates at the given SPEED. The movement continues until the camera reaches the destination.

Syntax:

VM_CAMERA_MOVE_TO X, Y, SPEED, AFTER_LOCK

Usage Example: Cinematic Camera Pan to a Distant Object

Imagine a cutscene where the camera needs to pan from the player’s current location to a distant, important object (e.g., a newly opened gate or a boss monster) to highlight it.

; In your cutscene script:

; Assume PLAYER_ACTOR_ID is the actor ID for the player
PLAYER_ACTOR_ID:
  .R_INT8 0 ; Example Actor ID

; Define the target coordinates for the camera pan
TARGET_GATE_X:
  .R_INT16 200
TARGET_GATE_Y:
  .R_INT16 150

; Define camera speed
CAMERA_PAN_SPEED:
  .R_INT8 2 ; Medium speed

; Temporarily unlock the camera from the player (if it was locked)
VM_CAMERA_SET_POS 0, 0, .CAMERA_UNLOCK ; Unlock camera first if it's following player

; Move the camera to the target gate position at a medium speed, then lock it there
VM_CAMERA_MOVE_TO TARGET_GATE_X, TARGET_GATE_Y, CAMERA_PAN_SPEED, .CAMERA_LOCK

VM_LOAD_TEXT TEXT_GATE_OPENED
VM_DISPLAY_TEXT
VM_IDLE 120 ; Display message for 2 seconds

; After the cinematic, move camera back to player and re-lock
VM_ACTOR_GET_POS PLAYER_ACTOR_ID, VAR_PLAYER_X, VAR_PLAYER_Y
VM_CAMERA_MOVE_TO VAR_PLAYER_X, VAR_PLAYER_Y, CAMERA_PAN_SPEED, .CAMERA_LOCK

; ... continue cutscene or game logic ...

TEXT_GATE_OPENED:
  .TEXT "A mysterious gate has opened!"
  .TEXT_END

; Camera lock constants (these would be defined globally)
.CAMERA_LOCK:
  .R_INT8 0
.CAMERA_UNLOCK:
  .R_INT8 1

In this example, VM_CAMERA_MOVE_TO TARGET_GATE_X, TARGET_GATE_Y, CAMERA_PAN_SPEED, .CAMERA_LOCK smoothly moves the camera to the TARGET_GATE coordinates. The CAMERA_PAN_SPEED controls the duration of the pan, and .CAMERA_LOCK ensures the camera stays fixed on the gate once it arrives. After the message, the camera pans back to the player.

Analogy to other programming languages/game engines: This is analogous to using a camera animation or interpolation function in a game engine:

It provides a way to create dynamic and visually appealing camera transitions, enhancing the player’s experience and guiding their focus.