Responding To User Interaction

Responding To User Interaction

You are here:
← All Topics

To respond to key press events use the “when key” event handler:

ship is a gemini
when key Left is pressed do
  ship.move left 1 in 0.1 seconds
end do

This will move the player’s ship 1 meter to the left whenever the left arrow key was pressed.
You can add as many event handlers as you like.

ship is a gemini
when key R is pressed do
  ship.turn right 30 in 0.1 seconds
end do

when key L is pressed do
  ship.turn left 30 in 0.1 seconds
end do

You can also respond to mouse click events:

ship is a gemini
when mouse left is pressed do
   ship.turn left 45 in 1 second
end do
Previous Ray-Casting Between An Entity And Another Group Of Entities
Next Rotating A 3D Model