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 /
  • Help Room /
avatar image
0
Question by hilmimarzuqi · Mar 01, 2016 at 02:00 PM · arrayaihashtable

How to store interaction using Hashtable and use AI to act on it

I found out there is a hashtable function in Unity, and I have been figuring out how to implement it in my game.

My game has a series of obstacles and requires a player to navigate and maneuver themselves to reach the finish line. I was wondering how I could make it so that when the player reaches an obstacle and do for example: Move right, Jump, Move Right, Move Left; it will be stored as a value on the hashtable for that specific obstacle.

Should I make it so the obstacle have a motion so that it can be stored as a key in the hashtable or are there alternatives in doing this?

I will be using the key-value from the hashtable as a basis for my AI to act based on the player's behaviour.

Comment
Add comment · Show 4
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 Salmjak · Mar 01, 2016 at 05:20 PM 0
Share

When I want unique keys for a set of numerical representations I usually bitshift the values into a ulong and use the ulong as the key. So if right = 10, jump = 14, left = 13 I would bitshift these 8-bit numbers into a 64-bit number. So first I would do something like (in pseudocode) Int16 newInt16 = ((Int16) right << 8) + (Int16)jump to get a 16-bit number. Then I would add two 16 bit numbers into a 32-bit number and two 32-bit into a 64-bit number.

avatar image hilmimarzuqi Salmjak · Mar 03, 2016 at 06:48 AM 0
Share

Can you explain a bit more? I have to declare right,jump, and left as an ulong value?

I'm quite lost in your explanation as I am new to Unity

avatar image Salmjak hilmimarzuqi · Mar 03, 2016 at 01:34 PM 1
Share

I just mean that you can encode a series of actions this way :) Ins$$anonymous$$d of e.g. adding them to a list. Adding an encoded ulong to a hashset in C# (or a Unity hashtable, I suppose they work the same way). I only have experience from C# and in C# you can't use e.g. an array as the key (it can't differenciate between two arrays depending on the objects IN the array). So you have to come up with a way to encode your array/list of commands into a single values. This is where bitshifting your command into a single ulong comes in handy. So your commands/movements should be 8-bit values (range 0-255). You then encode them in order of input to a "total input" ulong (by first bitshifting them into a 16-bit value, then a 32-bit value and last a 64-bit value). So you would be able to fit 64/8 = 8 inputs into a single ulong. So if you need longer sequences of input this won't work for you.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

68 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

Related Questions

Genetic Algorithm OverflowException: Number overflow: 1 Answer

how in order to pursue many targets? 0 Answers

How can I check for an inputted word against a list of words in a text file? 0 Answers

Choosing non null values from arrays for pathfinding 2 Answers

Need assistance with an primitive AI. 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