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 StrategicDesigner · Apr 08, 2015 at 03:31 PM · waypointrenamerenaming

Renaming issue for a waypoint system

Hello- I've been working on a waypoint system and have run into some trouble. The script should move unit to waypoint, which is then destroyed and waypoint2 is turned into waypoint, and the process is then repeated. However, while it reaches waypoint fine, waypoint2 will not turn into waypoint- it simply stops moving at waypoint. Any ideas as to why this is happening? Many thanks for any light you can shed on this!

 var unit: GameObject;
 var waypoint: GameObject;
 var waypoint2: GameObject;
 var duration: float;
 var collision: Collision;
 private var starttime: float;
 
 function start(){
 //sets start time for comparison on motion
 starttime = Time.time;
 }
 
 function Update () {
 //detects for the presence of a waypoint
 if (GameObject.Find("waypoint") != null){
 //if a waypoint is present, move it to its location over the given duration
 var startpos: Vector3 = unit.transform.position;
 var endpos: Vector3 = waypoint.transform.position;
 transform.position = Vector3.Lerp(startpos, endpos, (Time.time - starttime)/duration);
 }
 }
 function OnCollisionEnter(collision : Collision)
     {
 //when the unit collides with the waypoint, destroy it
     if(collision.collider.gameObject.name == "waypoint")
         {
         Destroy(waypoint.gameObject);
         waypoint2.name = "waypoint";
         waypoint = waypoint2;
         starttime = Time.time;
         }
     }


Oh, and another thing (although I'm probably not quite thinking clearly right now, it seems like it should be pretty simple, although I for some reason can't think it through...)- does anyone have any ideas as to how to make this unit-specific? Meaning that when a unit is 'selected' the waypoints (placed in gameplay) are applied to that unit in particular, since I'm going to be dealing with a bunch of them... Any ideas? Thanks!

Comment
Add comment · Show 4
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 winsjansen · Apr 08, 2015 at 04:11 PM 1
Share

I'd highly recommend doing it differently than this as this seems a bit unreliable, and a bit overly difficult way of doing it if you ever want 100 waypoints or something. I'd love to help you out making a more simplistic and reliable way of doing it if you want.

As for this code, I don't know whats wrong because I don't know how your scene looks like, also do you get any errors?

avatar image StrategicDesigner · Apr 08, 2015 at 04:19 PM 0
Share

The current code doesn't give any errors.

I'd appreciate any help on simplifying this down- what would you suggest? Thanks!

avatar image winsjansen · Apr 08, 2015 at 05:41 PM 1
Share

I'd just make a list of vector3, and then make the character move to the first one and then when he is there you just move to the second one, etc. This way you can also make him stop at different waypoints if you'd want.

You don't need to introduce the physics engine into this with collision detection and what not, I'd be happy to send you a unity package example if you'd like that.

You can reach me on Skype at; implementation92, if you want me to go into more details, I'm always happy to help out! :)

avatar image StrategicDesigner · Apr 08, 2015 at 06:27 PM 0
Share

Thanks! I stopped using collision detection and replaced it with distance detection. Thanks for your help!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is it possible to rename tabs in editor? 2 Answers

Force Rename of GameObject in Hierarchy 1 Answer

Waypoint Error. 1 Answer

Waypoint system teeling player where to go 1 Answer

How to setup car positioning with lots of routes? 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