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 dalinin · Oct 11, 2011 at 07:37 PM · arrayobjectmovecoordinatestrajectory

Moving an object along a prespecified trajectory according to coordinates from arrays

Dear community,

I've been looking for some hours in all along relevant web resources for the following problem but with no progress ... I want to move objects along prespecified trajectories in the space. The trajectories I specify via absolute x and z coordinates (2D-trajectory), which are arranged in separated arrays. Here is my code so far. The coordinates are just examples, nevertheless, I want to have the object moving from the previous in the array coordinate point to the next one:

var x = new Array (1000, 1500, 1500, 1500, 1000, 500, 500, 500);

var z = new Array (500, 500, 1000, 1500, 1500, 1500, 1000, 500);

var cnt = x.length;

var i=0;

function Start () {

 for (i=0; i<=cnt; i++) {
     transform.position.x = x[i];
     transform.position.z = z[i];
     }

}

So, for each point to on the trajectory the machine shall iterate over all the array elements. This should give as first coordination point (according to the array above) x1z1(1000, 500), the second x2y2(1500, 500) etc. When I run the script, however, the object doesn't do anything. I've also tried it via translate.position = Vector3(x[i], 0, z[i]) within the loop, and also here without the desired result.

Does anybody have an idea how to approach this problem? I thank you in advance for any help.

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 devast3d · Oct 11, 2011 at 08:43 PM

Antares project is already have what you are looking for: example of moving object alongside a spline. http://forum.unity3d.com/threads/47696-Antares-Project-(Open-Source)-1.5.5-Coming-soon

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 DaveA · Oct 11, 2011 at 07:52 PM

It would do all that iteration in the first frame rendered. You need to spread it out using an Update function. You may want to google 'waypoint following' also. And you can use arrays of Vector2 or Vector3 if you want to, to keep things tidy.

So specify some speed, and in the Update function you can use Math.Slerp to move the object along the current segment given Time.deltaTime. Look in the scripting manual for examples.

I suppose another way would be to insert a 'yield WaitForSeconds(1);' in the loop, so it would jump from point to point every second. But depends on what you want.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Gameboard, next position on a path 2 Answers

Is there any option to put objects together? 0 Answers

move from one point to another 2 Answers

Move object to several locations 2 Answers

Why do some objects have a different scale? 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