Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Miguet · Sep 09, 2015 at 06:58 PM · c#movement

Camera will not move between given points

I'm putting together a "raid cam" or "overview cam" for a given map in my shooter for an observing player to use to fly down a given preset path (to prevent griefing and cheating, this may change in my final build)

Unfortunately though I can get the program to invoke the given method, iterate through each of my points, and display this to the debug console, my player camera does not move from the very first start point. I'm attempting to use the Vector3.MoveTowards function at the moment but if there is a better way to move the camera between the points I am open to that.

The code is as follows, and heavily commented for clarity on my thought process:

     // Invoked from external function, takes precoded path and translates player between the given points
     public void FlyThroughPath(List<Vector3> path){
         Debug.Log ("FlyThroughPath"); 
         // If the flightpath is not empty
         if(path.Count > 0){
             // Enable the fly through (Externally tracked)
             enabled = true; 
             // Sets the start point as the first point in the track
             StartPoint = path[0]; 
             Debug.Log ("Start point is set as " + StartPoint.ToString());
             // moves the player immediately to this start point
             transform.position = StartPoint; 
             // For each point in the given path we'll get the current position of the camera and the next point
             foreach (Vector3 point in FlightPath){ 
                 // The first point move is redundant as the player is already at the start point
                 // Get the current position for the start point
                 StartPoint = transform.position; 
                 // The end point is our given point in the FlightPath
                 EndPoint = point;  
 //                StartTime = Time.time; // Not used at the moment
                 // Move controller between points
                 // Invoked to move between the given points
                 FlyToNextPoint(StartPoint, EndPoint); 
             }
             // When done we disable the fly through (Externally tracked not used yet)
             enabled = false; 
         }
     }
 
     // Takes two points and transforms the player camera between them at a preset speed
     public void FlyToNextPoint(Vector3 start, Vector3 end){
         Debug.Log ("FlyToNextPoint");
         // Grab the time for movement speed and duration
         // Snag the player's last chosen speed for consistency
         m_speed = flyMotor.m_actualSpeed; 
         // put together the time we want to use between the two points
         float t = m_speed * Time.deltaTime; 
         // Move the player between the given points at the given speed
         Debug.Log ("Flying to " + end.ToString() + " from position " + start.ToString());
         // Move the player camera towards the next point from the given start point
         transform.position = Vector3.MoveTowards(start,end, t); 
     }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Sep 09, 2015 at 08:23 PM

The position needs to be updated per frame. Either from Update() or in a coroutine. Instead of executing a foreach that calls FlyToNextPoint(StartPoint, EndPoint); try calling a coroutine that takes the entire path:

 public IEnumerator FlyPathCoroutine(List<Vector3> path){
     float lerpTime = 0f;

     for (int i = 0; i < path.Count; i++)
     {
         lerpTime = 0f;
         transform.position = path[i];
         while (lerpTime < 1f)
         {
             yield return new WaitForEndOfFrame();
             lerpTime += Time.deltaTime * m_speed;
             transform.position = Vector3.Lerp(path[i], path[i+1], lerpTime);
         }
     }

     yield return 0;
     }
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

2 People are following this question.

avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Most efficient/fastest way to rotate object around another object 0 Answers

Changing the landing and switch directions of standard assets TPC controller 0 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