is there a way to assign north south to an object?

Hi,

I am pretty new to unity3d, so i m asking in hope that there’s someway to this.
what i m trying to do is have a panel, the panel would have two cube on each side of the panel. the two cube is 10x, 5y,and 1z. sitting on each edge of the panel, so you have a walkway for a hall. all of this is inside an empty gameobject call hallway

I want to be able to have another gameobject look at the hallway object and determine if its looking at the side with the cube or if the side its facing is the side without the cube.
The hallway object can can randomly turn 90 %. the second object cannot touch the hallway object.

I hope i m explaingin this correctly.

You could take the position of both cubes and subtract the viewer’s position from it. This way you get a vector from the viewer to the cubes.

Vector3 Vcube1 = Cube1.position - Viewer.position;
Vector3 Vcube2 = Cube2.position - Viewer.position;
Vector3 LookDirection = Viewer.forward;

float dotCube1 = Vector3.Dot(Vcube1.normalized, LookDirection);
float dotCube2 = Vector3.Dot(Vcube2.normalized, LookDirection);

The one with the higher dot product is the one that is mostly in line with the look direction so is likely to be the one you’re looking at.

Looking at the comments on the original post I probably misunderstood the question.

Checking if you’re looking at the cube or the opposite direction

You can check whether you’re looking at the cube or not with a single dot product of that cube with the LookDirection. If it’s above 0 it’s ranging from almost perpendicular to looking at the object to fully looking at the object. If it’s below 0 it’s ranging from almost perpendicular to facing away from the object. And zero would be perpendicular.

Assuming the vectors were normalized before you got the dot product you can easily get the angle by doing:

float angle = Mathf.Acos(dotProduct);

Otherwise you’ll have to do:

float angle = Mathf.Acos(dotProduct / (V1.magnitude & V2.magnitude));

You completely lost me , as mentioned i m still pretty new to unity3d.
I did however tried a few scenarios and found that i can attach a custom property to the empty GameObject (GO) during runtime as all GO for the maze is generated at Runtime via Resources.Load().

what i end up doing:

public class wProperties : MonoBehaviour
public class wProperties : MonoBehaviour{
bool bForward;
bool bBack;
bool bLeft;
bool bRight;

  public setAvailPath(bool isAllow, iType){
     switch(iType)
     {
        case 0: 
           bForward=isAllow;
           break;
        case 1:
           bBack=isAllow;
           break;
        case 2:
           bLeft=isAllow;
           break;
        case 3:
           bRight=isAllow;
           break;
     }
   
    public bool getForward(){return bForward;}
    public bool getBack() {return bBack;}
    public bool getLeft() {return bLeft;}
    public bool getRight() {return bRight;}
}

on the main script, i would reference the script component to the GO and ask if forward/backward (z coord) is available, or left/right (x coord). if it is not, than i can re-randomize the current GO with a different maze piece.

I have not completely tried but on the generator project but did test the properties above on a new project and the values returned as needed.

Thanks.