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 asimov · Jun 26, 2012 at 10:12 PM · cameraprefabitweenpath

Alternatives to iTweenPath for creating path for camera

Continuing on from comments below. Each section has a script attached to it which does 2 things (called ThisSectionInfoManager).

  1. Finds its Endpoint

  2. Contains a public Transform array storing the path points positions, etc.The array is called 'RailMarkersList')

The code for this is as follows:

 public class ThisSectionInfoManager : MonoBehaviour 
 {
     public Transform EndPoint;
 
     public Transform[] RailMarkersList;
 
     void Start () 
     {
         EndPoint = transform.Find("sectionend");
     }
 
     void Update () 
     {
 
     }
 }
 ------
 

3 sections are maintained at all times with the camera starting in the first [0]. Once it approaches the start-point of the following section [1], a new section is generated and the first removed. In this way, the camera is always just entering the first section.

Now, a script called SectionManager generates and aligns the new section at the end. At the same time, the script that deals with the path following (CameraPathFollow) accesses the SectionManager script to find out what the first section of the array is (CurrentlyLaidSectionList[0]). It then goes on to access that section's script mentioned earlier (ThisSectionInfoManager) to copy its path points array (called RailMarkersList) into an array here (called Section_1_path, for instance). it then goes ahead and follows the path as we talked about below.

The CamerPathFollow script is as follows;

 public class CameraPathFollow : MonoBehaviour 
 {
     // Tranform arrays to hold the empty objects that form the path of the camera.
     // Points dragged in from Inspector - One array for each section.
     public Transform[] Section_1_path;
 
     public Transform[] Section_2_path;
 
     public Transform[] Section_3_path;
 
     public Transform[] Section_4_path;
 
     public Transform[] Section_5_path;
 
     public Transform[] Section_6_path;
 
     //
     float t = 0;
 
     // Variable to hold the tag of the section that the camera is in front of [0]
     private Transform sectionToFollow;
 
     // Reference to the Parking Lot object
     private GameObject parkingLotObj;
 
     //private SmoothQuaternion sr = new Quaternion();
 
     private SmoothQuaternion sr = new SmoothQuaternion();
 
     public float CameraSpeed;
 
     void Start () 
     {
         // Gain access to the Parking Lot object
         parkingLotObj = GameObject.Find("Parking Lot");
 
         sr = transform.rotation;
 
         sr.Duration = 0.5f;
     }
 
     void Update()
     {
         // Set the nextSection variable to hold the tag of the section in the second element [1] of the 
         //  CurrentlyLaidSectionList List - this is the one that the camera is always about to enter
         sectionToFollow = parkingLotObj.GetComponent<SectionManager>().CurrentlyLaidSectionList[0];
 
         // use swtih statement to decide which Transform array above to use for the path of the camera,
         // depending on which section is in CurrentlyLaidSectionList[1] at the time.
         switch (sectionToFollow.tag)
         {
             case "Section_1":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_1_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
 //                  transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_1_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
 //                    Debug.Log("Entering Section 1");
 
                     break;
                 }
 
             case "Section_2":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_2_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
                     //                  transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_2_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
 //                    Debug.Log("Entering Section 2");
 
                     break;
                 }
 
             case "Section_3":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_3_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
                     //                  transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_3_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
 //                    Debug.Log("Entering Section 3");
 
                     break;
                 }
 
             case "Section_4":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_4_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
                     //                  transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_4_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
 //                    Debug.Log("Entering Section 4");
 
                     break;
                 }
 
             case "Section_5":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_5_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
                     //                    transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_5_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
 //                    Section_5_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
                     //                    transform.position = Spline.MoveOnPath(Section_5_path, transform.position, ref t, CameraSpeed);
 
 //                    Debug.Log("Entering Section 5");
 
                     break;
                 }
 
             case "Section_6":
                 {
                     Quaternion q = new Quaternion();
 
                     // Copy the RailMarkersList into our array here so that the camera has the positions of the 
                     // markers after the section has been positioned
                     Section_6_path = sectionToFollow.GetComponent<ThisSectionInfoManager>().RailMarkersList;
 
 //                    transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, 30f);
 
                     transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, ref q, CameraSpeed, 100, EasingType.Sine, true, true);
 
                     sr.Value = q;
 
                     transform.rotation = sr;
 
 //                    transform.position = Spline.MoveOnPath(Section_6_path, transform.position, ref t, 300f);
 
                     //transform.rotation = Spline.RotationBetween(Section_6_path, );
 
 //                    Debug.Log("Entering Section 6");
 
                     break;
                 }
 
             default:
                 return;
 
 
         }// ends switch
 
     }
Comment
Add comment
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

2 Replies

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

Answer by whydoidoit · Jun 27, 2012 at 12:22 AM

You can use my Unity Path Following code and use MoveOnPath. It takes an array of transforms so they can move.

Comment
Add comment · Show 44 · 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 whydoidoit · Jun 27, 2012 at 12:25 AM 0
Share

Also this is a useful script to add to empty game objects that act as path points:

 using UnityEngine;
 using System.Collections;
 
 public class PathPosition : $$anonymous$$onoBehaviour {
     
     public int position = -1;
     
     public void OnDrawGizmos()
     {
         //Gizmos.DrawIcon(transform.position, "gold_pin-2.png");
         Gizmos.color = Color.yellow;
         Gizmos.DrawLine(transform.position, transform.position + transform.forward/2);
         Gizmos.DrawSphere(transform.position + transform.forward/2, 0.02f);
         if(position != -1) TextGizmo.Draw(transform.position, string.Format("position = {0}", position));
     }
     
 }
avatar image asimov · Jun 27, 2012 at 12:32 PM 0
Share

Sounds good, I shall give it a shot!

For the above script I'm getting the following error;

Error CS0103: The name `TextGizmo' does not exist in the current context

Thanks

avatar image whydoidoit · Jun 27, 2012 at 01:11 PM 0
Share

Oh sorry just delete that line, forgot that was one of $$anonymous$$e :)

avatar image asimov · Jun 27, 2012 at 03:09 PM 0
Share

No worries. Got that working, makes life a lot easier.

Also, would I need to use the version of $$anonymous$$oveToPath() that returns a rotation for this?

When placing the empty objects in the tubes for the prefabs/slots in Inspector, do I also need to rotate each of them so that their Z-axis is facing in the tube's forward direction?

Edit: O$$anonymous$$, so it's now following the path but not looking in the right direction. Have tried to download the Smoothing.cs file to use SmoothQuaternion as in your example from link above but its not working?

I don't suppose you could steer me in the right direction WRT to the rotation?

Thanks :)

avatar image whydoidoit · Jun 28, 2012 at 01:39 PM 0
Share

So there's a version of move on path that returns the desired direction I think. What's up with SmoothQuaternion? What effect are you seeing?

Does this code not work:

 #pragma strict
 
 var pathPoints : Transform[];
 
 var t : float;
 var sr : SmoothQuaternion;
 
 function Start() {
     sr = transform.rotation;
     sr.Duration = 0.5f;
 }
 
 function Update () {
     var q : Quaternion;
     transform.position = Spline.$$anonymous$$oveOnPath(pathPoints, transform.position, t, q, 0.5f, 100, EasingType.Sine, true, true);
     sr.Value = q;
     transform.rotation = sr;
 
 }
Show more comments
avatar image
1

Answer by jasperstocker · Feb 21, 2014 at 03:44 PM

Might I suggest Camera Path? It was designed specifically to animate cameras on a path with a very simple interface.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Switching Between (many) different iTween Paths (C#) 0 Answers

Camera switching with iTween Touch 1 Answer

PutOnPath iTween spline but not restrict in the up direction (jump) 3 Answers

Follow curved path with dynamic speed 2 Answers

How to move an object on a random path with iTween 1 Answer


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