- Home /
Final Fantasy style camera
Hi, I'm making a game and I want it to feel like a Final Fantasy. Like, each scene can have a panning camera or a rotating camera or a stationary camera. The panning camera needs to be able to move diagonally.
The idea is that we can set up a scene, make it look nice and artistic, so the player of the game would have no control over the camera except in that the player can walk out of a scene and the camera would then smoothly transition to a new point.
This is code I already have but it is insufficient:
pragma strict
var player : Transform;
var cameraPointA : Transform;
var cameraPointB : Transform;
var target : Transform;
var positionSpeed : float;
var rotationSpeed : float;
var rotate : boolean;
var pan : boolean;
function Rotate ()
{
Move ();
while (rotate)
{
transform.LookAt(player);
yield;
}
}
function Pan ()
{
while (pan)
{
transform.position = Vector3.Min(cameraPointB.position, Vector3.Max(cameraPointA.position, player.position));
yield;
}
}
function Move ()
{
while(transform.position != target.position || transform.rotation != target.rotation) // While the camera isn't in position or rotation
{
if (!pan) // If pan is false
{
transform.position = Vector3.MoveTowards(transform.position, target.position, positionSpeed); // Gets into position
}
if (!rotate) // If rotate is false
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, target.rotation, rotationSpeed); // Gets into rotation
}
yield;
}
}
This is a second script that triggers the previous script:
#pragma strict
var activeArea : boolean = false; // Returns if the current area is the active area or not
var moveCamera : CameraMovement; // Assigns the script "CameraMovement" to the variable "moveCamera"
moveCamera = Camera.main.GetComponent(CameraMovement);
var cameraPosition : GameObject; // Looks at the current position of the camera
var pointA : Transform; // Boundary of Mathf.Clamp
var pointB : Transform; // Boundary of Mathf.Clamp
var panning : boolean; // If true, the camera will move to follow the character
var rotate : boolean;
function OnTriggerEnter(other : Collider) // When the area is entered
{
if (other.gameObject.name == "Player")
{
activeArea = true; // Sets this to the active area
if (activeArea) // If this is the active area then execute
{
if (panning) // if panning is true
{
moveCamera.pan = true;
moveCamera.cameraPointA = pointA; // Sets the cameraPoint to pointA transform
moveCamera.cameraPointB = pointB; // Sets the cameraPoint to pointB transform
moveCamera.Pan (); // Runs the function "Determine ()" one the "CameraMovement" script
}
else if (rotate)
{
moveCamera.rotate = true;
moveCamera.Rotate ();
}
else // Otherwise
{
moveCamera.pan = false;
moveCamera.rotate = false;
moveCamera.target = cameraPosition.transform; // Sets the target on "CameraMovement" script to this object
moveCamera.Move (); // Runs the function "Move()" on the "Camera Movement" script
}
}
}
}
function OnTriggerExit() // When the area is exited
{
activeArea = false; // Resets this area
}
UPDATE: The script here has the camera following the player on every axis, which is what I want when panning is active. This script works exactly how I want except for that the player can approach the camera and the camera won't begin to back pedal it's position until it is level with the player (matches it's z co-ordinates)
Any help anyone can offer would be greatly appreciated! Thank you!
Can you clearly state exacty what is not working, and how it's not? Pretend we know nothing about FF and go from there.
Which Final Fantasy are we talking about? Because cameras differ a lot depending on the FF.
$$anonymous$$y bad! Could've sworn I had specified. I'm talking about the camera styles in FFVII, FFVIII, and FFIX. They're the ones that interest me. Thanks!
Answer by Andres-Fernandez · Apr 09, 2014 at 07:26 AM
To make cameras similar to those games I would create an animation clip for the camera in each scene (with those cool camera angles and movements from FFVII). The clip contains the position (and sometimes rotation) of the camera for that scene. Then set the speed of the animation (say the main camera has animation clip "scene01" attached) to 0:
animation[scene01].speed=0.0f;
and set the time of the animation depending on the position of the player. For example if player gets closer to point A then clip time decreases
animation[scene01].time=Vector3.Distance(player.transform.position, exit_A.transform.position)/max_distance_betweetn_exit_A_and_exit_B;
When you reach point A you change scene to the next one, with it's own camera animation clip. The key is to set the time of the animation depending on the position of the player within the scene (it doesn't have to be the distance, it can be global position or any other method you want).
Did a quick test with the clip system. I used a global z position to control the time and created a clip in which camera goes from 20 meters height to ground level and some rotation (really cool looking result). If you create the animation clip inside unity just remember to set it to legacy (animation type 1 in the debug panel).
Appears to work for all the testing I've done on it so far. I'll let you know if it happens to fall short with anything! Thanks for your answer!!
Your answer
Follow this Question
Related Questions
Controlling a character - Character is not moving. 0 Answers
PauseMenu - FPS Camera still moves when in PauseMenu 2 Answers
Left Click and Pan 2 Answers
Object jitters when camera is moving and is in the near? 0 Answers
Movin' camera in XYZ 6 Answers