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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by easilyBaffled · Jan 29, 2014 at 07:19 PM · cameracontrollerpathsplinepathfollowing

Dynamically Add Points to Spline

I am trying to create a randomly generated tube. I would like the camera to fly through the tube. To do this I am using the Hermite Spline Controller, the javascript version,and when a tube piece is instantiated I take a child from the front of it, and add it to the Spline Root. The new spline points are added properly, the red line connects them at least, but for some reason the camera won't follow. If I add a few points before hitting play the camera will go to those but no further. How can I make this work properly.

One theory that I have yet to test is that maybe the problem is that the objects I am adding to the spline are cylinders v ersus using empty game objects. The camera has moved to the first point that was created before play, the rest of the line was generated at game time.

It looks like I need someway to update the current Interpolator, but I am not sure how.

alt text

My code:

 public var tube_picker = new Array(0,0,0,0,1);//Ration of 0 to 1 is the percentage of Strait to Curve
 public var strait : GameObject;
 public var curve : GameObject;
 public var instatiate_position : Vector3 = Vector3.zero;
 public var instatiate_rotation : Quaternion = Quaternion.identity;
 public var tube_array = new Array();
 public var starting_tube_length : int = 8;
 
 public var spline_root : GameObject;
 
 function Start () {
     //Set up the initial tube
     for(var tube_piece_number : int = 0; tube_piece_number < starting_tube_length; tube_piece_number++){
         var new_tube_piece = Instantiate(strait, instatiate_position, instatiate_rotation);
         var new_piece_out = new_tube_piece.transform.Find("Out");
         instatiate_position = new_piece_out.position;
         instatiate_rotation = new_piece_out.rotation;
         tube_array.Add(new_tube_piece);    
         //Set up next target for Spline
         var new_piece_in : Transform = new_tube_piece.transform.Find("In").transform; 
         new_piece_in.parent = spline_root.transform;    
     }
 }
 
 function Update () {
     if(Input.GetKeyDown("a")){//Set on button press to control the process for debugging
         var picker_index = Random.Range(0, tube_picker.length); //Randomly choose between Strait and Curved
         var picked_option =tube_picker[picker_index];
         var picked_tube = strait;
         if(picked_option == 1){
             picked_tube = curve;
         }
         var new_tube_piece = Instantiate(picked_tube, instatiate_position, instatiate_rotation);
         //Set up position and rotation for the next piece
         var new_piece_out = new_tube_piece.transform.Find("Out"); 
         instatiate_position = new_piece_out.position;
         instatiate_rotation = new_piece_out.rotation;
         tube_array.Add(new_tube_piece);
         //Set up next target for Spline
         var new_piece_in : Transform = new_tube_piece.transform.Find("In").transform; 
         new_piece_in.parent = spline_root.transform;
         //Destory oldest piece to keep asset count low
         /*var oldest_piece = tube_array[0];
         tube_array.RemoveAt(0);
         Destroy(oldest_piece);*/
     }
 } 


screen shot 2014-01-29 at 2.17.21 pm.png (58.3 kB)
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 aeroson · Jan 30, 2014 at 01:34 AM

After brief look at the code i found this

 throw new System.Exception("Cannot add points after start");

So its most likely not good idea to do what you are trying to do.


Control points for the debug line are taken from transforms every OnGizmosDraw

But for the actual interpolation the transforms are only taken on Start()

Try to change line #134 of SplineController.cs from

 SetupSplineInterpolator(mSplineInterp, mTransforms);

to

 SetupSplineInterpolator(mSplineInterp, GetTransforms());
Comment
Add comment · Show 5 · 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 easilyBaffled · Jan 30, 2014 at 03:31 PM 0
Share

On first try it didn't work, but i have a question you said '#134 of SplineController.cs' but it was line 146 on SplineController.js. Were you looking at a different file or was this just a typo?

avatar image aeroson · Jan 30, 2014 at 03:53 PM 1
Share

Sorry, my bad i did look at the C# version. The problem here is with the t (Time) param, lets say you have 4 control points and you have t 0.5, you are now between 2nd and 3rd control point. If you add 4 more control points you are now between 4th and 5th. So you would have to change the SetupSplineInterpolator function to not normalize the Time. Also sorry about what i suggested. You really need to understand it and fit it to your needs your self.

avatar image easilyBaffled · Jan 30, 2014 at 04:11 PM 0
Share

Thank you for the clarification, do you think this line (adjusted for js) will work, or should I just dig around the file myself? Thought I should probably dig around anyways.

avatar image aeroson · Jan 30, 2014 at 04:30 PM 0
Share

It won't work, it's just an idea where to start digging.

avatar image easilyBaffled · Jan 30, 2014 at 09:58 PM 0
Share

After looking at the javascript version, it looks like that on each GIzmoDraw, it creates a new SplineInterpolator, but it doesn't add it to the gameObject like is done in the Start. This new interpolator is updated with the new nodes but it looks like it only draws.

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

19 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

Related Questions

Camera path with user entry stops 0 Answers

how to move along path with user controll 0 Answers

Camera stutters a lot when looking around (need help) 2 Answers

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

Issue with my camera controls 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