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 /
avatar image
1
Question by Abraham1532002 · Sep 15, 2017 at 01:03 AM · unity 5terrain3dcharactersubdivision

How to divide my terrain into selectable squares?

Hi.

My question is how can you divide the terrain into selectable squares where the characters are intanciados, the purpose of this is that I have to create lines or paths to attack my characters similar to the style vs Plants. Zombie, the player selects a division and this division lights up and when the player selects a character is intanciado in that division.

I have no idea how to do it, any suggestions will be helpful.

Thank you and forgive my English.

Comment
Add comment · Show 1
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 NorthStar79 · Sep 15, 2017 at 06:33 AM 0
Share

check tile and (or) grid systems.

1 Reply

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

Answer by tormentoarmagedoom · Sep 15, 2017 at 07:34 AM

Good day @Abraham1532002 !

There are a lot of ways to do this.

In one of my projects, i did a simple mode. I did all objects/characters/everything, must be placed at a coords multiple of 10, (10, 20, 30, -10 , -20 ...), this way is like creating a virual grid.

Then i calculate the position of the mouse in the world space, knowing wich position.x and pozition.z multiple of 10 is closer, using this (the same with Z coord):

 float floatMousePosX = Camera.main.ScreenToWorldPoint(Input.mousePosition.x);
 int gridMousePosX = 10 * Mathf.RoundToInt(floatmousePosX/10);
 //Divided the float by 10 and multilyed again by 10 will give you a rounded to 10 number

This way, you recieve a gridMousePos multiple of 10, (for example (10,-20) or (-230,150). Then If want to highlight or create objects in the grid, they must have a 10x10 size with center at some of this points.

If need more help on how to do this, just ask for more using @tormentoarmagedoom . I will check this question again in few hours!

If this helped you just a little, Upvote and Check the answer!

Bye :D

Comment
Add comment · Show 4 · 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 Abraham1532002 · Sep 15, 2017 at 10:04 AM 0
Share

Ok thanks, but you will not have an idea how to prevent a GameObject from being placed on top of another, that exists as a checker that says this is earth and this is a player, using his method.

avatar image tormentoarmagedoom Abraham1532002 · Sep 15, 2017 at 03:02 PM 0
Share

Yes you can prevent objects to be placed at same place, for example :

As all objects have/will have a exact place (10, 20 30), once something is placed, you only need to store that position in some variable, and when placing things make a loop that recalculate the random if the result is equal to some stored position.

Or, use colliders to respawn something if it spawns inside another collider

You can always create a script or go to assets store and download/buy one to create a scenario with grid.

$$anonymous$$ark the answer please! :D

Bye :D

avatar image Abraham1532002 · Sep 16, 2017 at 12:43 PM 0
Share

the last $$anonymous$$i question on my part, and sorry for the inconvenience, except I never had the need to do something like this, but, now, how can I make the grid where the mouse is placed, shine or something similar, that confirms its presence to the user. Thank you

avatar image tormentoarmagedoom Abraham1532002 · Sep 17, 2017 at 08:51 PM 0
Share

Hello @Abraham1532002 !

First, mark my answer as correct please :D

Then, you can do script that calculates the position of the mouse, and know then wich tile are you pointing

  float float$$anonymous$$ousePosX = Camera.main.ScreenToWorldPoint(Input.mousePosition.x);
  int grid$$anonymous$$ousePosX = 10 * $$anonymous$$athf.RoundToInt(floatmousePosX/10);

This way, grid$$anonymous$$ousePosX will be always the multiple of 10 closer to the mouse position.

Do the same for Z coord. Then in the Update() check every frame what grid$$anonymous$$ousePosX & grid$$anonymous$$ousePosZ is poiting the mouse. and you will have a realtime variable with the mouse grid position.

It's a pleasure to help! :D

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

170 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 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

Help me about terrain painting, some kind of mipmapping problems, idk. 0 Answers

[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ? 1 Answer

Infinite Runner Movement 2 Answers

3D Bacteria Game Environment 0 Answers

Cinemachine character animation help 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