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
0
Question by Jan_Julius · Aug 25, 2014 at 02:39 PM · performancepuzzle

Question about puzzle game checking for other objects

What would be the most efficient way of checking what happens on the picture? when 2 of the same colors touch? what are some good ways and what would you recommend using for this. the molecules can rotate 6 times.

I was thinking of using a raycast but I'm very affraid for my performance if I'd use that.

alt text

EDIT: this is also displayed in one of my replies to the topic but this will clarify what I mean and what situation I'm in.

Yes, the game is grid based there will be a grid full of these molecules and if lets say for example you have 3 molecules, you have the 2 I displayed on the picture and there will be an other one that connects with red to red on the other molecule that way there will be 3 molecules touching eachother in a line example but keep in mind that there can also be 4 or 5 lined up: alt text

The grid will contain an amount of molecules so they are clearly visible and easily clickable on any regular size mobile phone, 30-40 would be an amount, considering the fact that some of the molecules can be surrounded by other ones I would have to cast 3 raycasts from every single molecule that way from each color. Each molecule is built out of primitives, one sphere and 3 colored cilinders, nothing fancy there won't be anything fancy either. I was first planning to do the touching with raycasts so I wrote code that would support that easily, how it's done now is when you click on one of the molecules it will up the status and then it will change the rotation of the object to the rotation that belongs to the status.

Here you can see what I mean:

     public int status;
 void Start(){
         status = Random.Range(0, 6);
     }
 void Update(){
 switch(status){
         case 0:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 300);
             break;
         case 1:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 240);
             break;
         case 2:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 180);
             break;
         case 3:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 120);
             break;
         case 4:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 60);
             break;
         case 5:
             gameObject.transform.eulerAngles = new Vector3(
                 0, 0, 0);
             break;
         }
 
             }
     public void StatusUpdate(){
         if(status == 5)
             status = 0;
         else 
             status++;
     }

I hope I have given enough information this way, thanks in advance!

@NoseKills Could you give me an example of this as I don't really seem to understand what you mean? currently I create a grid with molecules and they spawn a certain way so the edges touch eachother.

How can I diagonally cast a raycast?

Comment
Add comment · Show 6
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 meat5000 ♦ · Aug 25, 2014 at 02:22 PM 0
Share

Raycast isn't that intensive. Your computer isnt going to blow up from your CPU overloading :P

Just try it.

avatar image Jan_Julius · Aug 25, 2014 at 02:50 PM 0
Share

I'll give it a shot, don't you think/know a better way of getting this done though?

avatar image robertbu · Aug 25, 2014 at 03:14 PM 0
Share

Without specifics, it is hard to give your suggestions:

  • I assume these pieces are built out of primitives?

  • What moves them so they touch? Physics? Transform? Other?

  • How do you plan on detecting touching?

  • Will the parts snap together, and if so, will you hold the result together using parent child, or a FixedJoing, or Other?

  • How many molecules will exist in the scene?

  • How many different kinds of molecules will there be?

  • How many will touch in a given frame?

  • Will a single molecule touch more than one other molecule during a frame?

avatar image Pecek · Aug 25, 2014 at 03:47 PM 0
Share

A raycast per rotation isn't expensive at all - for example, if you want realistic ballistics, you have to cast a ray every frame/bullet until it hits something. Now imagine a gunfight betwen automatic weapons. And that isn't really expensive either.

avatar image NoseKills · Aug 25, 2014 at 03:49 PM 0
Share

Like @robertbu said, wihout knowing more it's hard to know what would be the best approach.

If this is any sort of a grid based game without free movement and physics, i would certainly do the logic part as an array of objects that user input manipulates and i would update the positions of your graphical objects (3d models) based on that abstract representation.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Aug 25, 2014 at 03:30 PM

You could use colliders and Kinematic rigidbodies with constraints.

Colour checking can be performed in OnCollision functions.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Pro opinion wanted: what fps is too low? 1 Answer

s-pen GUIUtility.BeginGUI performance problems 0 Answers

Best way to access game objects 0 Answers

Unity performance issues in my scene. 1 Answer

Performance and memory 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