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#movementvector3

Camera wil not move between given points, stays at first given point

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 Eudaimonium · Sep 10, 2015 at 12:40 PM

You appear to be making the same mistake I just commented an hour back on different question,

Basically you have a logic for traversing the entire path within your own while/for/foreach loop. This results in entire logic for traversal (and the traversal itself) to happen in a single frame. When that frame gets rendered, your player/camera is already at the end of the path.

Remove the foreach loop, and implement the interpolation through the points logic using the Update loop, and move in small increments per each pass of Update loop (each frame) to actually have the object move.

Refer to my answer here: http://answers.unity3d.com/questions/1064238/unity-crashes-on-event-of-specific-code.html - just change the logic a bit so that when distance to your destination (the point within your list of locations) is smaller than threshold - you have arrived - instead of stopping movement, just change the destination to the next point.

If you need that solved in code, post it on Pastebin and let me know, I'll help you out.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

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

Need helping getting a character controller to jump 1 Answer

Move from one position to another in x seconds 2 Answers

Get a position relative to a gameobject 0 Answers

How can I make this object relative to the players position? 2 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