Implementing a compass

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Toothgapsy

Hello community, I am once again asking for your implementation aid :slight_smile:

I am currently trying to implement a compass for VR, it should always face the forward direction. I somewhat reached this using the look_at() function. My problem is that when pitching the compass the mesh and the texture showing the cardinal directions will collide in one another resulting in a look like this:

Anyone got a quick idea on how i could avoid this behaviour? I know it is kind of hard since you will it actually does what it should do, as it always points towards the north (forward) direction.

Why are the mesh and the texture two different objects? If you have to keep them separate for some reason, then instead of rotating the mesh, couldn’t you rotate a parent common to both the texture and the mesh?

Bernard Cloutier | 2020-03-06 01:59

I don’t really understand what you want to achieve. If you want to avoid clipping, but still have wind rose flat, you can, for example, make it render on top of that mesh. You could also make that mesh slightly transparent, or just put that wind rose higher.

kubaxius | 2020-03-06 13:25

:bust_in_silhouette: Reply From: Barrrettt

This help me: using A to B compass angle. If B is north of A the angle is 0 radians:

public float getDirection(Vector3 vA, Vector3 vB){
        //only plane XZ
        vA = new Vector3(vA.x, 0, vA.z);
        vB = new Vector3(vB.x, 0, vB.z);
        
        Vector3 dir = vB-vA; 
        float angle = Vector3.Forward.AngleTo(dir); //angle with "nort"
        
        //clockwise
        if (dir.x<0){
            angle = (2*Mathf.Pi) - angle; 
        }
        return angle; 
}

In python same logic.