Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Skellington · Apr 02, 2014 at 01:30 AM · cameramovingpan

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Apr 02, 2014 at 01:31 AM 0
Share

Can you clearly state exacty what is not working, and how it's not? Pretend we know nothing about FF and go from there.

avatar image Andres-Fernandez · Apr 08, 2014 at 01:26 PM 0
Share

Which Final Fantasy are we talking about? Because cameras differ a lot depending on the FF.

avatar image Skellington · Apr 08, 2014 at 02:48 PM 1
Share

$$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!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andres-Fernandez · Apr 09, 2014 at 11:10 AM 0
Share

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).

avatar image Skellington · Apr 10, 2014 at 01:53 AM 1
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges