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
1
Question by R2D2 · Dec 01, 2010 at 05:37 AM · waypointsairplane

waypoints for airplane - non horizontal

I'm trying to set up waypoints for an airplane "in air" at various Y heights. All scripts I have tried rely on horizontal locations. How can I acheive an enemy finding the location of a way point in the closest x,y,z location? rather than only on one axis.

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

Answer by adrenak · Jan 01, 2012 at 06:06 AM

Some code that I wrote a while back. Just sctter the waypoints in 3D space and drag them in order one by one into waypoints array. And it will move in that loop that you have

 var waypoints : Transform[];
 var currentlyMoving2 : Transform;
 var speedOfMotion : float;
 var movingIndex : int;
 
 function Start(){
 
     currentlyMoving2 = waypoints[0];
     movingIndex = 0;
     
     if(Vector3.Distance(transform.position , waypoints[0].position) < 0.5){
         currentlyMoving2 = waypoints[1];
         movingIndex = 1;
     }
 }    
 
 function Update () {
 
     if( Vector3.Distance(transform.position , currentlyMoving2.position) < 0.5){
         
         if(movingIndex == (waypoints.Length - 1)){
             movingIndex = 0;
             currentlyMoving2 = waypoints[movingIndex];
         }    
         else{    
             movingIndex ++;
             currentlyMoving2 = waypoints[movingIndex];
         }    
     }    
     
     transform.position = Vector3.MoveTowards(transform.position,                                           currentlyMoving2.position, Time.deltaTime * speedOfMotion);
 }


You might wanna add a few things such as facing the waypoint towards which the object is moving. I didn't need it in my project so I didn't write all that. To make the object find the nearest waypoint, just use something like this in the start function:

 var shortestDistance : float;
 shortestDistance = Vector3.Distance(transform.position , waypoints[0].position;
 nearestWaypoint : waypoints[0];
 for(int i = 1 ; i < waypoints.Length ; i ++){
     if( Vector3.Distance(transform.position , waypoints[i].position) < shortestDistance ){
         nearestWaypoint = waypoints[i];
         shortestDistance = Vector3.Distance(transform.position , waypoints[i].position;
     }
 }

After this,simply make the object face nearestWaypoint and move towards it.You will need to have a boolean variable that becomes true when the object reaches the nearest waypoint and only when this variable is true, the update function does all that it needs to do, moving to the next waypoint and face them and all.

Hope this helps

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 Bmacbmac · Jun 04, 2020 at 02:35 AM

Use a vertical beam that has the code saying that when it is hit by the plane it will make the plane go back to it when it crashes

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

2 People are following this question.

avatar image avatar image

Related Questions

FPS Waypoints not working right 1 Answer

How to move along a group of waypoints at a certain speed? 2 Answers

Waypoints script: add 2 animations 0 Answers

how to set a variable in prefabs or use an object in the hierarchy/prefab section in my script 1 Answer

PacMan IA of ghost using nodes/waypoints 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