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
1
Question by User12345 · Feb 24, 2011 at 01:36 PM · gridsystemsimple

Grid system detect where player is

Hi guys,

I would like to have a very simple grid ontop of a terrain. the grid system only has to detect in which grid segment the player is and was.

my goal is to let a player search for items in a grid segment and if the player has already searched in a grid segment he cannot search it again. like in this game.

http://armorgames.com/play/5766/planet-noevo

I have found 50000 Tutorials for grid systems but none of them is what I want. I am not a good programmer so I am not able to rewrite that kind of code to my needs :(

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

Answer by Alec-Slayden · Feb 24, 2011 at 03:03 PM

How about this:

Set a null object to a far corner of your terrain, and put the player inside of this null object for local space (or alternatively have world zero at the corner of the terrain, and use global space)

With that setup, you can easily have a script grab the player position at any given time, and divide it by the grid size to determine what grid he's in.

Using a 2 dimensional array you could keep track of information for the grid square.

EDIT:

Here's a Javascript example of a method, set up for a 100 x 100 grid of 1.0 x 1.0 squares.

var PlayerTransform : Transform;

var gridSize_X : float = 1.0; //Row value var gridSize_Z : float = 1.0; // Column value var gridInfo = new String[100, 100];

private var currentRow : int; private var currentColumn : int;

function Update(){ // Here we do the math, and make sure to clamp it within the array's bounds

 if (gridSize_X != 0) //no dividing by zero!
 currentRow = Mathf.Clamp(PlayerTransform.localPosition.x / gridSize_X, 0, 99);

 if (gridSize_Z != 0)
 currentColumn = Mathf.Clamp(PlayerTransform.localPosition.z / gridSize_Z, 0, 99);

}

function Dig(FoundItem:String){

 // If the square isn't null, we must have assigned a string to it already!
 if (gridInfo[currentRow, currentColumn]){
     Debug.Log("This place has already been dug.");
 }
 else{
     gridInfo[currentRow, currentColumn] = FoundItem;    
 }


}

How you would call the dig function is up to you. Right now you'd pass a string into it with the name of what is found, but you could presumeably set up the code determining what is found in the dig function itself.

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 User12345 · Feb 24, 2011 at 03:28 PM 0
Share

yeah that might work. thanks!

avatar image User12345 · Feb 24, 2011 at 03:55 PM 0
Share

Wow thanks a lot!

avatar image Alec-Slayden · Feb 24, 2011 at 03:56 PM 0
Share

no problem, glad it's helpful!

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

Grid Based Movement System (pokemon like) 1 Answer

Where can I learn to make a tile system? 1 Answer

Power Generation? 2 Answers

Clicking on objects 2 Answers

Best solution for Grid-based building system? 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