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 raklar · Jan 07, 2014 at 06:59 PM · transformposition

transforming position

I'm trying to transform the position of an object once a variable in another script becomes true, but of course, it doesn't work properly, it starts from position B once the variable (csScript.wave) becomes true. Here is my code;

     var pointB : Vector3;
     var pointC : Vector3;
     var pointD : Vector3;
     var pointE : Vector3;
     var pointF : Vector3;
     var csScript : TargetCollision;
     // private var endPos : Vector3 = new Vector3(0.0, 40.0, 0.0);
     function Start () {
     
  //animation.Play("running"); 
     var pointA = transform.position;
     while (true) {
    //while(csScript.wave){
 //if(csScript.wave){
     yield MoveObject(transform, pointA, pointB, 3.0);
     yield MoveObject(transform, pointB, pointC, 3.0);
     yield MoveObject(transform, pointC, pointD, 3.0);
     yield MoveObject(transform, pointD, pointE, 3.0);
     yield MoveObject(transform, pointE, pointF, 3.0);
    // }
     }
     }
      
     function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3 , time : float) {
      if(csScript.wave){
         transform.position = startPos;
     transform.LookAt(endPos);
     var i = 0.0;
     var rate = 1.0/time;
     while (i < 1.0) {
     i += Time.deltaTime * rate/8;
     // if(csScript.wave)
     thisTransform.position = Vector3.Lerp(startPos, endPos, i);
     yield;
     }
      }
      
     }
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 Gruffy · Jan 07, 2014 at 09:04 PM

pull your "while(true)" conditional code out of start() and whack into Update().. it is only running the code once and consequently only moving it a single time (3 units per frame/second). After that the code is never called again. Why? Because Start() is an initialisation method. update is the game loop, this is where code will be read over and over again.

BTW, what is a MoveObject, something I have never heard of outside of bespoke code for Unity. Normally, you call to transform.Translate(); feeding the argument with vector positions and float distance...like so...

 transform.translate(this.transform.position, objectToMoveTo.transform.position, 3.0f );

Your objectToMoveTo would be another GameObject/Transform that you have specified (perhap as a public GameObject in your script that you could assign in the inspector to the script etc. just comment and I will get back to you if not, else if it answered your question help others to find it too by marking it an answer.

there is another way, a better way... LERP

This allows something known as linear interpolation between to specified objects and a float value for the length of time to take getting from one point to another. Check out the reference above, it is the way forward for you, with respect to better handling of your transforms translations (at this point anyway)

take care bud.

Gruffy.

Comment
Add comment · Show 3 · 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 raklar · Jan 07, 2014 at 10:44 PM 0
Share

Thank you for your answer, I just created that function to sort of make way points, it is moved from point A - B then B - C so on, with the help of that $$anonymous$$oveObject function in the bottom of the script there. I feel like your code will work, thanks again, will grant your answer once I change function name Start to Update.

avatar image raklar · Jan 22, 2014 at 06:30 PM 0
Share

It doesn't even move when they are in the update function

avatar image Gruffy · Jan 28, 2014 at 11:38 AM 0
Share

You would need to call the function "$$anonymous$$oveObject" from Update, this will continue to call the loop you have created in your code to translate the object. You would also be then using the positions you have made in Start for your way points as an iterative value that gets evaluated against its current position. something like....

for(int i = 0; i< waypoints.length i++) { Transform nextWp = new Transform(); nextWp = waypoints[i+1]; transform.LookAt(nextWp ); transform.Translate(waypoints[i].position);

}

The above isn`t a resolve for your issue, just a guide as such.

here is a script package that you should really take a peek at. It is written in Java/UnityScript but i can also pop over a C# version that I had to implement a while back. I see you are using UnityScript though so thought this was best

import it and load the scene, press play and have a look at whats going on there.

Take care, hope this solves it for you :) Gruffy waypoints

flythroughwaypoints.zip (208.9 kB)

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

Change position of camera on scene load? 1 Answer

Create a straight gradient equation with a grid of 3d objects 1 Answer

Following another object's position/rotation like parent/child relationship? 4 Answers

How do you set the initial value of a variable to an objects current position in unity? 1 Answer

Create an animation with variables? 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