Wiki

Case Status
Log In

Wiki

 
Home ยป Samples»Swamp»MainCamera FSM»Look Around
Index
Navigation
Community Wiki

Look Around

Pan the camera based on the position of the mouse cursor. The further the mouse from the center of the screen, the faster the camera rotates in that direction.

Additionally we want a dead zone in the middle of the screen where the camera doesn't pan.

Actions

Get Mouse X

Store the current x position of the mouse in the mouseX variable.

Normalize the value so it's in the range 0-1.

Comment

Comments are a good way to self document actions.

Sample Curve

The mouseX value ranges from 0 (left) to 1 (right). We need to convert this to a camera rotation in degrees. 

We can scale the value later, right now we want a base direction and falloff; so we want 0 to become -1 and 1 to stay 1.

We also want a "dead zone" in the middle. And we want smooth falloff. See the final curve below.

 

Float Multiply

Now that we have camera rotation in the range -1 to 1, we need to multiply it by the maximum panSpeed.

We could bake this speed into the curve, but it's more convenient to tweak a single panSpeed number than to edit a curve.

Rotate

The camera is parented to a CameraPivot to get some nice parallax motion as we rotate. 

This means we should rotate CameraPivot, not the camera directly.

To pan the camera we rotate around the Up/Y axis.

The Space doesn't matter in this case because CameraPivot has no parent.

We check Per Second because panSpeed is defined in degrees per second. A good idea if you want your operations to be frame rate independent!

 

Mouse Cursor

Draw a simple custom cursor.

 

Sample Curve: The transformation curve that converts mouseX to a camera rotation:

Tags:

Last modified on 12/16/2010 8:28 AM by User.

  • RSS Feed