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
-2
Question by AnaRhisT · Jun 22, 2010 at 04:29 PM · movewaypoint

continue moving without yielding.

I've a character that walks from waypoint 0 to 1 from 1 to 2 from 2 to 3. the character reaches from 0 to 1 it waits 1.5 seconds, and then when it gets to the 2nd waypoint it doesn't wait 1.5 seconds, and so on..

http://09duck.pastebin.com/qVREn4NB

var waypoint : Transform[]; var speed : float = 3; var currentWaypoint : int; var loop = true; var test;

function Update () { animation.wrapMode = WrapMode.Loop; var controller : CharacterController = GetComponent(CharacterController); if(currentWaypoint < waypoint.length){ var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position;

 if(moveDirection.magnitude &lt;= 1.5){
     print("magniute");
     animation.CrossFade("idle");
     speed = 0;
     WaitThreeSeconds();
     if(test){
     test = false;
     currentWaypoint++;
     }
     if(currentWaypoint == 3){ currentWaypoint -= 3; }
 }
 else{
     animation.CrossFade("walk");
     speed = Random.Range(0.8,2.01);
     RotateTowards();
 }

} //print(moveDirection.magnitude); controller.SimpleMove(moveDirection.normalized * speed); }

function RotateTowards () { var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position; while(Vector3.Distance(target, transform.position) >= 1.5){ transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection), 0.5* Time.deltaTime); transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); yield; } }

function WaitThreeSeconds(){ yield WaitForSeconds(1.5); test = true; }

Comment
Add comment · Show 5
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 JonManatee · Jun 22, 2010 at 05:20 PM 1
Share

You don't really say what your problem is, perhaps you could be more clear

avatar image Pirate___man · Jun 22, 2010 at 05:23 PM 0
Share

I think AnaRhisT is trying to say that the delay only works the for the first way point

avatar image qJake · Jun 22, 2010 at 06:05 PM 0
Share

You're yielding inside of Update(), and you shouldn't do that. You can ONLY yield with a coroutine, nothing else (at least, that's the only recommended way, anyway).

avatar image AnaRhisT · Jun 22, 2010 at 06:16 PM 0
Share

so if i want to use yield even if i refer it a function i cant use the update in any way?

avatar image Novodantis 1 · Jun 22, 2010 at 07:14 PM 0
Share

No, that's different. The reason it won't work in Update itself is that Yield holds up the routine running that particular function. So the rest of your Update would not be called until the yield releases it, which would likely cause odd behaviour.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Mike 3 · Jun 22, 2010 at 08:16 PM

Try put WaitThreeSeconds(); down by a line into the if(test) block

That should sort it

Comment
Add comment · Show 2 · 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 AnaRhisT · Jun 22, 2010 at 10:36 PM 0
Share

Thanks for that hint, i also needed to check "if(!test)"

avatar image Mike 3 · Jun 22, 2010 at 11:32 PM 0
Share

You're doing the exact same thing again. You really shouldn't be calling all these coroutines from inside update. You probably have about 300 coroutines running simultaneously moving your object. if you change your while to if in RotateTowards, and remove the yield, it should fix things properly

avatar image
-1

Answer by AnaRhisT · Jun 22, 2010 at 10:35 PM

Solution :

var waypoint : Transform[]; var speed : float = 3; var currentWaypoint : int; var loop = true; var test;

function Update () { animation.wrapMode = WrapMode.Loop; var controller : CharacterController = GetComponent(CharacterController); if(currentWaypoint < waypoint.length){ var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position;

 if(moveDirection.magnitude &lt;= 1.5){
     test = true;
     print("magniute");
     animation.CrossFade("idle");
     speed = 0;
     if(test){
     WaitThreeSeconds();
     currentWaypoint++;
     }
     if(currentWaypoint == 3){ currentWaypoint -= 3; }
 }
 else{
     if(!test){
     animation.CrossFade("walk");
     speed = Random.Range(0.8,2.01);
     RotateTowards();
     }
 }

} //print(moveDirection.magnitude); controller.SimpleMove(moveDirection.normalized * speed); }

function RotateTowards () { var target : Vector3 = waypoint[currentWaypoint].position; var moveDirection : Vector3 = target - transform.position; while(Vector3.Distance(target, transform.position) >= 1.5){ transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection), 0.5* Time.deltaTime); transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0); yield; } }

function WaitThreeSeconds(){ yield WaitForSeconds(1.5); test = false; }

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Goes faster when moving to monster's transform 1 Answer

Having Unity lock up when running a path script 2 Answers

Move waypoint mouse click 0 Answers

How to move to random position? 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