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 Yharooer · Jul 01, 2013 at 01:05 PM · movementtriggertilecollisiondetectionlocomotion

Tile-Based Movement - Collision

Hi,

I am working on a game where I need my main character to have tile based movements. I think I can do this, but am still working on it at the moment.

The problem I face now, is that I want my main character not to walk into walls, or walk off the ground into water etc. I was thinking of making this happen by tagging the floor and walls, so if below the main character, there is an object tagged as "floor" and if towards the direction it's travelling there is not one tagged as "wall" only then would the character move.

Would this be the most efficient way to do it, or is there a much simpler way? Thanks!

Comment
Add comment · Show 3
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 Hoeloe · Jul 01, 2013 at 01:09 PM 1
Share

It's probably not a good idea to have each tile a separate GameObject if you can avoid it, it may cause problems if you have large maps. The standard way of dealing with this is similar to what you suggested, though - give each tile a "type", and test that type before you move into it. It's efficient as it's just a string or integer comparison, as opposed to actual collision detection.

avatar image pickle chips · Jul 01, 2013 at 03:36 PM 0
Share

Yes, I also believe the approach you're taking may be the wrong way to do it. For the best and most efficient way to make a tile based game, I HIGHLY reccomend watching this youtube playlist. It covers everything you need to know in depth, and will greatly help you in the future. It may be a bit long, but for everything you'll learn it's worth it. He also explains ALL the concepts extremely well, so you will hardly need to worry about not understanding anything.

Here is the link, and if you have the time it is definitely worth your while.

avatar image Yharooer · Jul 01, 2013 at 10:40 PM 0
Share

Hi, Sorry, but its not that sort of randomly generated terrain that I want. I want more of for example, a maze which is different on every level, and the player needs to get to the end. $$anonymous$$aybe I'm missing something further into the videos so I'll still watch them. Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by SubatomicHero · Jul 01, 2013 at 01:12 PM

If you are talking about, for example, a simple 4 x 4 grid you need to setup the grid once it has been instantiated.

You could have a class that holds properties for each tile:

 public class tile
 {
     bool hasWater;
     bool isOccupied;
     // other stuff

     // important bit here
     public tile north;
     public tile south;
     public tile east;
     public tile west;
 }



and when you create each piece of the grid, instantiate a new object of type tile. Then you need to setup where the north, south etc tiles are.

Then your movement would check like so:

 void Move() // for exmaple
 {
     if(!tile.north.isOccupied) // if the north tile is free
     {
         // you can move there
     }
 }

Hope this helps..

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 Yharooer · Jul 01, 2013 at 01:41 PM 0
Share

I mainly use JavaScript. Is there an equivilant of a class in JavaScript?, although I'm probably going to learn c# soon.

avatar image SubatomicHero · Jul 01, 2013 at 01:52 PM 0
Share

Try this link for "classes" in JS

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

19 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

Related Questions

Cannot stop character movement upon trigger 2 Answers

Charecter Controller like in Merry Bear game(Cube based game). 0 Answers

Im NOT Switching Scenes!! PLEASE HELP!! 1 Answer

Strange position change when triggered 0 Answers

How to make sprite move behind part of tile 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