• 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 NGKrush1 · Jul 24, 2012 at 05:52 PM · c#randompathfinding

help: pathfinding in random maze.

Hi!

I'm trying to recreate a game much like these old Locomotion games. In it, there is a block of 8x6 squares, which together form a maze of traintracks. A train moves over the tracks(the player has no control) and the player needs to rotate the squares to make the track longer and longer.

alt text

Now, I've got my head around the whole 8x6 grid, which is created randomly. But I have no idea where to start with the AI of the train. Do I preanimate each of the squares? Do I use A* pathfinding set to a tight grid?

Any tips or help in the right direction? I'm working in c#, if it helps.

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 whydoidoit · Jul 24, 2012 at 06:10 PM 0
Share

Is there really AI in that game - doesn't the train just follow the track rather than choose a direction? There don't appear to be any pieces for a decision.

So are you asking how to get it to animate itself through the different sections?

avatar image Dev Solo · Jul 25, 2012 at 12:07 AM 0
Share

If im understanding this right... randomly generated tiles will not work well for this since it will be impossible to finish the level sometimes

avatar image Dev Solo · Jul 25, 2012 at 12:23 AM 1
Share

but even with tiles that can be rotated.. if its random.. what stops the computer from generating ALL straight tiles?

avatar image NGKrush1 · Jul 26, 2012 at 09:57 PM 0
Share

@dev solo: I have a calculation going that generates various straights and corners based on difficulty.

@whydoidoit: i guess the train follows the track, like you say. The train doesn't have a $$anonymous$$d of it's own, but just goes straight or takes a corner. I have never made any form of computer controlled players/opponents in a game yet, so I was wondering how other people would go at it. Using real AI seems silly for something so silly, but how do i get the train to follow the path otherwise?

avatar image whydoidoit · Jul 26, 2012 at 10:01 PM 0
Share

I'd be creating a series of path points and using a spline path follower to move through each individual tiles.

At its simplest that is just a set of key points on the tile and as the train enters it then move towards the next path point until the tile is exited. A spline would make the curves smoother but is probably not necessary.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dev Solo · Jul 25, 2012 at 12:15 AM

As for your question:

Make a 3d room over every square consisting of 4 box colliders (in the tile prefabs) each wall of the box would have a different trigger:

If you enter one trigger... set it so the other triggers are inactive.

Set the wall triggers that dont have a track connecting to them so they destroy your train (or whatever you want them to do)

Set the ones with the tracks to move your train further forward, and turn if necessary.

It will need some fine tuning (on the corners especially) but it should work perfectly fine. Doing this method also allows you to convert it to 3d graphics later on if you wish.

Hopefully you know how you would do this. Its fairly simple but I have no knowledge in C#, or how your game works.

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 NGKrush1 · Jul 26, 2012 at 10:00 PM 0
Share

Hmm, it's an interesting solution. I think which would work very well. But how would I get the train to know when the take a corner (and into which direction?)

avatar image Dev Solo · Jul 26, 2012 at 10:03 PM 0
Share

Thats all in the tweaking. basically just script it to move forward on its Z (perhaps slow down on corners) and rotate on Y slowly as it progresses (lerp to +/-90)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

AI pathfinding waypoints 1 Answer

A While Loop in a path finding system is freezing, how can I fix this? 0 Answers

[Solved] Find the position ALONG a raycast 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