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
1
Question by user-2236 (google) · Apr 21, 2010 at 02:59 PM · positionpathwaypointsplineroute

How can I collect the positions of my waypoint objects which mark out a path or route?

Hi guys, im quite new to unity so this is probably something quite simple. Im attempting to use this code here:

http://forum.unity3d.com//files/smoothcurve_208.js

to get my object to follow the curve - all is working fine.

However, instead of getting the 'waypoint' position info via the inspector this way:

var points : Vector3[];

( where i have to type the x,y,z into the inspector )

Is there any way of getting the x,y,z info of the waypoint objects i have added to the scene and then having that populate the Vector3 array in the code??

preferably using this way:

var waypoints : Transform[];

I think its all the builtin array stuff thats throwing me.

Thanks

Danny

p.s. should i delete this question from the forum as i have repeated it there ?

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
1

Answer by duck · Apr 21, 2010 at 03:17 PM

Yes I do this often (for example to collect the waypoints which mark out a racetrack).

If your waypoints are numbered, you can search for them by name like this:

var markersList = new ArrayList(); var markerNum = 0; var searching = true;

while (searching) { markerNum++; var markerName = "routemarker" + markerNum; var markerObject = GameObject.Find(markerName);

 if (markerObject != null)
 {
     markersList.Add(markerObject.transform.position);
 }
 else
 {
     searching = false;
 }

}

Debug.Log("Found " + markersList.Count + " route markers");

If you need to, you can then convert the ArrayList to a built-in array like this:

var markers = markersList.ToArray(typeof(Vector3));

If your route markers are numbered with zero padding (i.e. 001, 002 etc), you can find their names like this:

var markerName = "routemarker" + markerNum.ToString().PadLeft(2,'0');

I think it's best to numerically name your markers, however if your markers aren't numerically named, you could get them all by assigning a custom tag to them all, and then using FindGameObjectsWithTag, however I'm not 100% sure that they will always be collected in the correct order.

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
avatar image
0

Answer by Herman-Tulleken · Jul 16, 2010 at 01:05 PM

If you use the array of Transforms as you suggest, you can conveniently drag nodes into the array, and copy their positions with the following snippet:

var waypoints : Transform[]; // for inspector private var waypointVectors : Vector3[]; //for use in script

function Start () //assumes nodes will not change wile the game is running { waypointVectors = new Array(waypoints.length);

 for(i = 0; i < waypoints.length; i++)
 {
     waypointVectors[i] = waypoints[i].position;
 }

}

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

No one has followed this question yet.

Related Questions

choose random waypoint 1 Answer

Rotate, follow randomly generted waypoints? 2 Answers

Cloning An Object Along A Path Between 2 Points 1 Answer

How To Re-use model Like Subway Surfer & Temple Run Game? 3 Answers

Moving rigidbody along spline, and being able to use physics 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