Flying to the Moon

Testing the game to see what the maps look like is a little tricky, as you need to pause the game and fly around. To make it easier you will create a binding that will allow you to toggle fly mode.

Add Fly Binding

To toggle on and off fly mode, you will need to create a binding for the key.

  1. In the Hierarchy, find the Default Bindings object, which can be found under the Gameplay Settings folder.
  2. Double click on the Default Bindings in the Hierarchy to open up the Bindings Manager window.
  3. Bottom right of the Bindings Manager window click on the Add Binding button and select Add Basic Binding.
  4. In the Action field for the new binding, enter Toggle Fly Mode.
  5. From the dropdown for the Keyboard Primary column, select the E option.
  6. From the Networked column, toggle the networking for this binding so it is on. This is so the binding can be listened to on the server.

Create PlayerServer Script

Create a new script called PlayerServer and put it into the Server Scripts folder in the Hierarchy. This script will listen for when an action is pressed (for example, the key E), and toggle fly mode.

Create ActionPressed Function

Create a function called ActionPressed that will be called anytime an action is pressed. If the action matches the binding you created for toggling fly mode, then a check is done to see if the player is already flying. If the player is flying already, then the script will activate walking, otherwise active flying.

local function ActionPressed(player, action)
	if action == "Toggle Fly Mode" then
		if player.isFlying then
			player:ActivateWalking()
		else
			player:ActivateFlying()
		end
	end
end
Code language: Lua (lua)

Connect Event

Connect up the event actionPressedEvent by passing in the ActionPressed function to it as the input.

Input.actionPressedEvent:Connect(ActionPressed)
Code language: Lua (lua)

The PlayerServer Script

local function ActionPressed(player, action)
	if action == "Toggle Fly Mode" then
		if player.isFlying then
			player:ActivateWalking()
		else
			player:ActivateFlying()
		end
	end
end

Input.actionPressedEvent:Connect(ActionPressed)Code language: Lua (lua)

Test the Game

Test the game to make sure you can toggle fly mode by pressing E.

With this ability, you can now fly through your generated map and get an overhead of what it looks like as you modify the generation algorithm.

Flying Speed

If you find that the flying speed is too slow, then you can modify the settings on the Third Person Player Settings object in the Hierarchy under the Fly category. Setting the Max Fly Speed to a higher number will allow you to move around quicker when in fly mode.

Scroll to Top