Orientation / Compass?

I want to add a compass. I have searched for ways to programme this although none of the topics I found were what I wanted.

I want to parent the azmith/GUITexture to my player but freeze its rotation to the terrain. Is this possible??

place an invisible object north of the needle and make the needle a child of the player. Then put a script on the needle and use Transform.LookAt(invisibleTarget). Should work just fine…

I’m not using a needle. My player is in the center, and as the player turns the dial turns around him/her.

can you give a bit more info then (2d or 3d game etc)? maybe a screenshot. if you use a plane for the texture that is the compass, can’t you make it a rigidBody and use freezeRotation in the inspector window?

Its a 3d game, I am displaying it as you would a mincam. So picture a circle around a player, I need that cirle to be parented to the player but use the rotation of the terrain, basically stay static as the terrain is to the player, then if the player changes direction the circle will rotate in the mincam.

so then if I’m not missing something here, you could set the rotation of the child (in every frame) to the rotation of any static object in your game? The as the player’s camera rotates with the player, the compas should stay in position. Or am I missing something?

Yeah thats exactly right, you’re not missing anything.

I just need to know how to script it right, I am not getting any results from what I am trying, but no errors.

Ok, thinking about it again, making the compass a child is not the solution. Keep them seperate and then use this code. Just tested it and it works perfectly. The code goes onto the compass gameObject.

using UnityEngine;
using System.Collections;

public class compass : MonoBehaviour {


    public Transform worldTarget;
    public Transform player;
	
    void Start () {
	
	}
	
	
    void Update () 
    {
        transform.position = player.transform.position;
        transform.localEulerAngles = worldTarget.transform.localEulerAngles;
	}
}

Yes that does work perfectly. I see what I was doing wrong also.

One thing though, if the player is traveling on an incline it shows on the world target, but that is not bad, i may leave it.

I appreciate you help;)

Yeah it will. If you don’t want that to happen, you might want to break it into seperate axis and set the Vector3.up to that of the player and the others to that of the world. if you know what I mean. But like you said, it might actually look kindoff funky if you leave it liek that.