- Home /
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.

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: 
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?
Raycast isn't that intensive. Your computer isnt going to blow up from your CPU overloading :P
Just try it.
I'll give it a shot, don't you think/know a better way of getting this done though?
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?
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.
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.
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.
Your answer
Follow this Question
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