Friday Script – Galv’s Camera Control

Camera control will pan to the puzzle, and stay centered there until we tell it otherwise.

Camera control will pan to the puzzle, and stay centered there until we tell it otherwise.

     If you want to get the most out of RPG Maker, learn Ruby. In the meantime, lots of talented scripters have done the work for you. Every Friday, The Iron Shoe features a fun script and goes into detail about how to use it. It also covers a little bit of Ruby each time so you can make even more out of the script.

Today’s script is Galv’s amazing Camera Control! RPG Maker’s camera controls are clunky at best. Calling “scroll map” can be tricky when you don’t know where the player is starting from, and what if you want the map to stay put while the player moves?? For all of you planning grandiose cut scenes, Galv’s Camera Control will do the work for you.

Copy/paste the script just above “main” in your list of scripts, and away we go!

Changing the Camera From Inside an Event
Once you’ve added Galv’s Camera Control, any event – be it an NPC on the map or a Common Event – has access to a trigger called “script call.” This allows you to access the camera control script. In this window, you can type a few things:

  • cam_follow(eventid, speed) – use cam_follow to have the camera follow an NPC – or any event – instead of your character. Don’t actually type “eventid,” instead use the number found at the top of the event. Same with speed, don’t type “speed.” Instead, you’ll choose a number from 0-6. This will determine the speed at which the camera pans from you to the NPC, before locking onto the NPC. 1 is very slow, 6 is very fast. 0 is a special case, it’ll snap the camera to the NPC, rather than panning to them. You can choose not to use speed at all, in which case it will default to 6. That is, typing cam_follow(3) is the same as typing cam_follow(3,6). Both will cause the camera to pan to event 3 at speed 6, then follow it.
  • cam_set(x,y,speed)  – use cam_set to lock the camera to a specific coordinate. “X” and “Y” should be replace with the map x and map y (not screen x or screen y!) that you want to lock to. Speed functions the same way as above. Again, speed isn’t necessary, it will default to 6.
  • cam_center(speed) – set the camera back on the player, in good ol’ default RPG Maker mode. Again, speed isn’t necessary – feel free to type cam_center()
The most basic setup - if a player steps on this tile, lock the camera to a coordinate.

The most basic setup – if a player steps on this tile, lock the camera to a coordinate.

A Note About Speed

As mentioned above, speed can be 0-6. 0 is a special condition which “snaps” the camera, but what about 1-6? If you open up the “scroll map” trigger in any event in RPG Maker, you’ll notice that the speeds listed all have a number associated with them – Galv’s 1-6 are the same numbers! So if after years of playing with RPG Maker you just know that “normal” speed is what you want, then set your speed to 4.

Digging Deeper With Ruby

These 3 script calls have infinite application, and you aren’t bound to use numbers at all. Consider the following example:

Player Peter just leveled up, and got an awesome new ability called Shadow Form. This ability allows his spirit to leave his body. The spirit can walk through walls and even activate switches, but only lasts for 5 seconds! It also has a pretty small range – you wouldn’t want your spirit wandering off too far.

     There are a lot of components to building this ability, but let’s talk about what the camera is doing during this time. As the game progresses, the camera follows Peter as normal. But when activating Shadow Form, the camera stays focused on Peter’s body, while the player controls Peter’s spirit, wandering around in a 17×13 screen for a few short seconds.

There are a few ways to do this, but for teaching purposes let’s do it this way; set the camera to an x,y based on a variable. In the event editor, when Peter activates Shadow Form, we’ll set two variables (for my purposes, variables 1 and 2) to Peter’s x and y respectively. Then we can call the following in a script:

x = $game_variables[1]

y = $game_variables[2]


     This way, wherever Peter was when the event was called, the camera will stay there! On expiration, we’ll call cam_center. Those experienced with Ruby might ask why I didn’t just write the following:

cam_set($game_variables[1], $game_variables[2])

     Script calls in RPG Maker events have trouble processing multiple items in a line. This line will actually crash your game. While it’s acceptable in the full blown script editor, it’s no good in an event’s script call.

We should build a return function too, or Peter might never return!

We should build a return function too, or Peter might never return!

Intermediate Challenge

We could’ve used Galv’s amazing script to make Peter’s Shadow Form without setting any variables. Using cam_follow, how might we do that?

Advanced Challenge

Let’s say you’ve got the cam set for an extended period of time, and in the middle of it the player quits. When you reload the game, the camera will no longer be set. How might we fix it so that saving/loading preserves the camera position?

Post your thoughts / screenshots / walkthroughs concerning either challenge in the comments section, and we’ll reveal the answers to both in 2 weeks!


2 thoughts on “Friday Script – Galv’s Camera Control

  1. You could fix that by making a switch be set once the script is activated and another auto run event doing the same thing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s