Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Nov 12, 2016 at 09:35 PM · logic

Need help with logic.

Hello! Currenty im making a game, where you should make spaceships to capture planets. Im stuck in making proccess of choosing the closest path of chosen way. Here is a picture of what i mean. S - starting point, E - end of path, red arrows show the closest path. alt text I was thinking about system like this: Each planet has a list of connectet planets. (Planet 1 has list of 2,4,5) etc. Then you just take ending planet and look for planets, that are connected to it, check if connected planets arent your starting point, if not choose the next one planet. Then store all that paths and just choose the closest one. Im stuck in implemeting way how to store all that paths. Thanks in advance.

I understand that its a bit confusing, so you can ask me anything you dont understand.

-2-bmp.jpg (19.5 kB)
Comment
Add comment · Show 2
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 doublemax · Nov 12, 2016 at 10:01 PM 0
Share

If you have very small number of planets you can just try all combinations. Above that it becomes a non-trivial problem, known as "traveling salesman problem." Google for that and you'll find possible solutions.

avatar image $$anonymous$$ · Nov 12, 2016 at 10:37 PM 0
Share

Is there a way to store all possible combination within one loop?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by spraw · Nov 13, 2016 at 03:57 AM

The A* algorithm should do exactly what you are looking for, given that you already have a node based system and everything...

http://arongranberg.com/astar/front

http://www.policyalmanac.org/games/aStarTutorial.htm

Comment
Add comment · Show 1 · 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 $$anonymous$$ · Nov 13, 2016 at 11:41 AM 0
Share

Thanks, maybe that exactly what i was looking for.

avatar image
0

Answer by UrielKane · Nov 13, 2016 at 11:12 PM

Helo dear Le_Valius i'm sertainly not a profesional at this, and sure there someone can have a better solution. Anyway i'm going to tell you how i will do it if i was developing that logic. I'm currently developing a prototype of a FPShooter so i have to deal with pathfinding and waypoints systems. I found some years ago on the web a really simply and very useful waypoint system. That is ideal for car racing like games, that store in every waypoint, with are the next one and have a return type function that let you get the next waypoint. Of course may be you would amplify its versatility and functions.

After saying that, what i would do in your place is. Think the solar sistem like a web so every planet have stored wich ones are conected. You can do an array variable with every planet conected. Then you have to create probably a very tricky loop where you are going to check and eliminate those ones wich are not conected until the end of the path. So you propose a very simply example wich can become very complex in more extended scenarios. But lests stay in the simply.

Lets say that you want to go from Start to End like in the example. So in the midle of the path you have a node planet how is not the end but a bridge to rich it. So in the loop you probably have to see is. 1) where are you, and what planets are linked to that one. 2) Take those linked planets and search wich ones have the end path (I have to say that this in first attempt can work on that simply example but in a larger scenario may be can become so tricky). Construct an array of those planest that have linked the end destination. And from here everything should be less problematic. Now you have to compare the distance of full path each other, and pick that one that is the smaller.

You may be notice that this is pretty functional in that specific scenario that you bring to us. But lets say that the system is a web of docens or even hundreds of planets. That's when the big trouble begun, becouse i have not taking into account that is important to kept track of every node of the path. So to achive a good result may be you will have to do a tremendous scan of the entire web. May be eliminating some obious ponts where is no need for a check.

This is just a general idea i really dont know if it's going to work, or work properly. Is just what i probably will do if i was trying to achive what you prupose. I dont remember where i found the waypoint system, but if you need it just ask and i will share it.

Good Luck!

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 $$anonymous$$ · Nov 13, 2016 at 11:58 PM 0
Share

Thank you mate, i will try your idea for sure. Would be thankful if could link your waypoint system, but no problems if you forgot! :)

avatar image UrielKane · Nov 16, 2016 at 08:52 PM 0
Share
 #pragma strict
 
 // The start waypoint, this is initialized in Awake.
 // This variable is static thus all instances of the waypoint script share it.
 //public  DirectionalWaypoint start;
 
 // The next waypoint, this variable needs to be assigned in the inspector.
 // You can select all waypoints to see the full waypoint path.
 public var next : DirectionalWaypoint;
 
 // This is used to deter$$anonymous$$e where the path start.
 public var isStart : boolean = false;
 // This is used to deter$$anonymous$$e where the path end.
 public var isEnd : boolean = false;
 
 // Returns where the AI should drive towards.
 // position is the current position of the car.
 function CalculateTargetPosition (position:Vector3, nDistance:float) : DirectionalWaypoint{
     // If we are getting close to the waypoint, we return the next waypoint.
     // This gives us better car behaviour when cars don't exactly hit the waypoint
     if (Vector3.Distance (transform.position, position) < nDistance) {
         return next;
     }
     // We are still far away from the next waypoint, just return the waypoints position
     else {
         return this;
     }
 }
 
 function CalculateDistance (position:Vector3) : float {
     // If we are getting close to the waypoint, we return the next waypoint.
     // This gives us better car behaviour when cars don't exactly hit the waypoint
     return Vector3.Distance (transform.position, position);
 }
 
 // This initializes the start and goal static variables.
 // We have to do this inside Awake because the waypoints need 
 // to be initialized before the AI scripts use it.
 // All Awake function are always called before all Start functions.
 function Awake () {
     if (!next)
         Debug.Log ("This waypoint is not connected, you need to set the next waypoint!", this);
 }
 
 // Draw the waypoint pickable gizmo
 function OnDrawGizmos () {
     Gizmos.DrawIcon (transform.position, "waypoint.png");
     if (next) {
         Gizmos.color = Color.green;
         Gizmos.DrawLine (transform.position, next.transform.position);
     }
 }
 
 // Draw the waypoint lines only when you select one of the waypoints
 function OnDrawGizmosSelected () {
     Gizmos.DrawIcon (transform.position, "waypoint.png");
     if (next) {
         Gizmos.color = Color.red;
         Gizmos.DrawLine (transform.position, next.transform.position);
     }
 }
avatar image UrielKane · Nov 16, 2016 at 09:04 PM 0
Share

That's the code and you will need a gizmos icon to work properly. It has to be a transparent icon and name it Waypoint. Anyway i'm going to se if i can send to you the icon.

Here a folder with both the script and the gizmos icon. Luck in your project. https://mega.nz/#F!z8hX2$$anonymous$$ZL!B8FIv8PUS2kl_a3wtA0SRQ

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

59 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 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 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 avatar image avatar image

Related Questions

TransformPoint and InverseTransformPoint 2 Answers

How destroy a object and it's similars 4 Answers

Check to see if any object in a list meets set of requirements 0 Answers

Provide user virtual currency after every 24 hrs. 1 Answer

Scenes and objects organization in games like Stellaris or Endless Space... 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