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 chunjai · Dec 27, 2010 at 09:05 PM · arraypathcoordinatesdice

Gameboard, next position on a path

I'm creating a game with a sort of 'Candy Land' mechanic, but with dice... Roll a dice, move piece as many spaces as the dice rolled. I need to get the player's current position and define its next position (pseudo :: nextpos = currentPos + 1; moveTo nextPos x diceRoll). I thought the best way would be defining the gameboard in an array, and nextPos would basically be the next key in the array, but I'm still unsure how to do that, or even if it's the best solution. Any guidance is appreciated.

Edit :: I'm using JavaScript in unity. The path traveled is linear, so where I'm really needing help is how to 'go to' the next position in an array from the current position. I'm not sure how to code 'this key in the array is the current position. this key + 1 is the next position, and the next position x diceroll is where the piece should move to'.

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
Best Answer

Answer by Jason B · Dec 27, 2010 at 11:29 PM

The path traveled is linear, so where I'm really needing help is how to 'go to' the next position in an array from the current position.

It's difficult to explain, but it should be very straightforward. In theory, each array variable holds a position on the game board, correct?

And each array space is numbered.

I'm pretty sure that all you have to do is, at the start, assign your game piece's position to, for instance, BoardSquare[0], where array slot 0 is the game board starting place (I'm also explaining in C# terms as I don't know Javascript, sorry about that). Also, keep a variable inside the game piece that "remembers" which board square array slot it's occupying. Let's say it's called myCurrentSquare.

From there, it's extremely simple. If you roll a 6, you'd tell the piece to move itself to BoardSquare[(myCurrentSquare + 6)]. It should then move to the 6th array vector.

Does that make sense?

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 Jason B · Dec 28, 2010 at 12:18 AM 0
Share

Actually, that'd be the 7th array vector if you start counting from zero, but you know what I mean. :)

avatar image chunjai · Dec 28, 2010 at 12:57 AM 0
Share

yesss, this totally makes sense. i didn't know you could do an equation like that (myCurrentSquare + 6) in the array. will give this a go tonight.

avatar image Jason B · Dec 28, 2010 at 01:03 AM 0
Share

Yep. The array number is just an integer. You can plug in any integer variable name into it ins$$anonymous$$d, or even math (I'm not 100% if you can do math inside the array brackets, but I'm fairly sure you can).

avatar image
1

Answer by Jesse Anders · Dec 27, 2010 at 10:33 PM

If the path is strictly linear, then an array would likely be a reasonable solution. If you need help with the details, let us know what language you're using, and what part of the implementation you need help with. (You can edit your original post and add this information.)

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

No one has followed this question yet.

Related Questions

How to add LineRenderer positions based on an Array of GameObjects 2 Answers

How to Slerp through values inside a 2D array ? 1 Answer

Problem with the climbing of stairs ( character piloted by coordinates) 0 Answers

Enemy offset, gallaga style game (space invaders) 0 Answers

Instantiating for every Xpos and Zpos 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