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
0
Question by Daniyal · Jul 23, 2016 at 08:27 AM · detectiontileslineedgeborder

How to detect that an object (ball or disk) stays in between the tile and on the border of a tile?

I have a single 3D tile made in maya, and I created a tile surface with code, each tile has its own border , I want to detect that if my player walks over the tiles and if player stops on the tile border it will show me some message or if the player stops in between the tile it will show me another message. Please help me. @hamstar , @Tomer , @Starwalker , @AlienFreak , @Furjoza .

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

Answer by rocket350 · Jul 23, 2016 at 06:17 PM

One possibility would be to add a collider to every tile when creating them, the collider being smaller than the tile. If the player ends his move outside all of the colliders, you can display a message, as he is no longer directly on any of the tiles

For that you would have to add the following lines to the code where you create each of those tiles at runtime:

 int x;   //  Play around with these values so that
 int y;   //  while the player is still in an acceptable
 int z;   //  position on the tile, he touches a collider with these dimensions

 //The next lines needs to be repeated on every created tile
 //so be sure to place it in a foreach loop or something similar
 Collider tempCollider = tempTile.AddComponent<Collider>();
 tempCollider.isTrigger = true;
 tempCollider.x = x;
 tempCollider.y = y;
 tempCollider.z = z;
 tempTile.AddComponent<BoundaryChecker>();

Here is the code for the BoundaryChecker.cs class:

 using UnityEngine;
 using System.Collections.Generic;
 
 public class BoundaryChecker: MonoBehaviour {
     private static List<BoundaryChecker> touchingColliders;
 
 
     void OnTriggerEnter(Collider other) {
         if(other.gameObject.tag == "Player")
             touchingColliders.Add(this);
     }
     void OnTriggerExit(Collider other) {
         if(other.gameObject.tag == "Player")
             touchingColliders.Remove(this);
     }
     public static bool isPlayerOnTiles() {
         if (touchingColliders.Count == 0)
             return false;
         else
             return true;
     }
 }

When the player ends his turn, you can call the static function BoundaryChecker.isPlayerOnTiles() which returns a boolean depending on whether the player is touching any of the colliders or not, and display a message accordingly.

Note:
Your player GameObject must have the tag "Player".

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to detect the distance between two edges (2D sprites) 1 Answer

C# How to Detect Edges of a Collider 0 Answers

Detect object borders to add collider 0 Answers

Gothic-like climbing and edge detection 0 Answers

How to Get Image edge size 2D?? 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