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 joyishilukamer · Mar 30, 2021 at 11:09 AM · scripting beginnertilemap

Trying to figure out tilemap movement based on dice roll

So I'm making a board game but I'm a bit stuck on how I would go about giving each map tile a specific movement.
I want the player to always start on the Star icon when the game is first run no matter where the star icon may be on the map.
Then the player will role a die and depending on the outcome they will move that many spaces away from their current position, however moving on the grass and dirt tiles will take 1 movement of the dice roll, moving on the forest tiles will take 2 movements of the dice roll, and moving in the ocean will take 3 movements of the dice roll.
I'm stumped as to how to do this so any help would be appreciated. Thank you in advance! alt text

mapidea.png (95.1 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by KoenigX3 · Mar 30, 2021 at 04:13 PM

Sorry, I don't quite understand, but I'll try to help you.

I would create an 2D integer array, where the integers identify the type of the tile. Then I would roll the dice, and get an integer, representing the number of movements I have. On each movement, I would check the type of the target tile, and decrease my movement integer according to the type. If I didn't have enough movement, then I would not move my character.

 int movement = Random.Range(1, 7); // The upper limit is exclusive
 
 // This is the logic you can use when making your moves
 if(movementCost[targetTileType] <= movement)
 {
    // Move character to the tile
    movement -= movementCost[targetTileType];
 }


Here, movementCost is an integer array, that stores the movement cost of each tile type. For example, if you identify dirt with index 0, forest with index 1, and ocean with index 2, it's [1, 2, 3]. You can get the variable targetTileType from the 2D integer array that I've already mentioned.

Now, this would work only if you moved your character step by step. If you wanted to reach a farther tile, a problem would arise. For example, let's say that you want to go up and right - the problem here is that you could also go right and up. Using a different path can make a difference if the tiles are different. This problem can be solved by pathfinding algorithms.

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 joyishilukamer · Apr 04, 2021 at 01:06 AM 0
Share

Thank you, I haven't tried it yet because I've been adjusting other aspects of my game, but once I get back to tile movement I will try it out. I just didn't want to leave you hanging!

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

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

Related Questions

Add tiles with script 1 Answer

Pathfinding in 2d RPG 0 Answers

Prefab editor (tilemap) doesn't work? 0 Answers

Why is my tilemap disappearing in game mode?,My tiles disappear in play mode 1 Answer

does unity lightwave rp work with tilemaps? 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