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 Wolfshadow · Dec 09, 2016 at 02:57 AM · gridboxgrid based gamesensing

Approach to Sensing in a 4x4 Grid

Hello all, I have a game in which I need to determine which of 16 (4x4) irregular boxes a player is in. By irregular, I mean that they have different dimensions. i was wondering the approaches that I could take to sense which box the player was in. Should I use playerposition, oncollision, etc. Any ideas? Thanks for the help, and good day to you all.

--Edit--

so I have this code:

using UnityEngine; using System.Collections;

public class hammerhit : MonoBehaviour {

  public Rigidbody mole;
  public Vector3 molevector3;
 
 
  public Collider b1;
  public Collider b2;
  public Collider b3;
  public Collider b4;
  public Collider b5;
  public Collider b6;
  public Collider b7;
  public Collider b8;
  public Collider b9;
 
  // Update is called once per frame
  void Update () 
  {
      molevector3 = mole.position;   //sets molevector3 to mole position in realtime
      //Debug.Log (molevector3);            //returns molevector3, the mole position
      //Debug.Log (molevector3.x);          //returns mole x postition
 
 
  }
 
  void OnCollisionEnter (Collision col1)
  {
      if (col1.collider == b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8 || b9) 
      {

// Destroy (col1.gameObject); }

  }

}

and I attach it to the camera, which is my player. However, when the destroy (col1.gameobject) line is called, it destroys anything it touches, not just b1, b2, etc. Ideas?

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 NoseKills · Dec 09, 2016 at 07:19 AM 0
Share

Depends on what exactly you want. If a collider collides with another collider, it doesn't meant it is inside it. If the player must always be in just one of the squares, you should probably use player position and Rect.Contains() for example.

1 Reply

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

Answer by RobAnthem · Dec 09, 2016 at 06:19 AM

OnCollision is your best bet, you can make a player property called something like public int currentGrid; Then on collision just set the variable to whatever section you want. Trying to calculate the coordinates is only easy if your grid is consistent size.

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 Wolfshadow · Dec 09, 2016 at 09:47 PM 0
Share

so I have this code:

 using UnityEngine;
 using System.Collections;
 
 public class hammerhit : $$anonymous$$onoBehaviour {
 
     public Rigidbody mole;
     public Vector3 molevector3;
 
 
     public Collider b1;
     public Collider b2;
     public Collider b3;
     public Collider b4;
     public Collider b5;
     public Collider b6;
     public Collider b7;
     public Collider b8;
     public Collider b9;
 
     // Update is called once per frame
     void Update () 
     {
         molevector3 = mole.position;   //sets molevector3 to mole position in realtime
         //Debug.Log (molevector3);            //returns molevector3, the mole position
         //Debug.Log (molevector3.x);          //returns mole x postition
 
 
     }
 
     void OnCollisionEnter (Collision col1)
     {
         if (col1.collider == b1 || b2 || b3 || b4 || b5 || b6 || b7 || b8 || b9) 
         {
 //            Destroy (col1.gameObject);
         }
 
     }
 }

and I attatch it to the camera, which is my player. However, when the destroy (col1.gameobject) line is called, it destroys anything it touches, not just b1, b2, etc. Ideas?

avatar image Wolfshadow · Dec 09, 2016 at 11:22 PM 0
Share

@RobAnthem do you have any ideas based on my code that I sent?

avatar image RobAnthem · Dec 10, 2016 at 01:43 AM 0
Share

I'd either add a script to each box, or simply

     if(b1.bounds.Contains(mole.position))
     {
        molePosition = 1;
     }

avatar image Wolfshadow RobAnthem · Dec 10, 2016 at 02:54 PM 0
Share

thank you for your help

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

58 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

Related Questions

Create a grid on a cube? 0 Answers

Grid-based building system not working 1 Answer

grid-based block placement system with touch input 1 Answer

moving down blocks 0 Answers

My square are not alligned like a grid 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