Compass, Player direction

Hi,

In my game the player kills his enemies by shooting(its first person shooting game), and I wish to tell the player that he is going on the right direction(means any help like compass for user).

I am using Sprite to draw my compass nob and using sprite function to rotate nob as given bellow: -

private void rotateKnob( Sprite sprite, Vector2 pos )
{	
	Transform trans = sprite.client.transform;
	float x = pos.x - ( sprite.width / 2 );
	Vector3 newVector = new Vector3( x, ( sprite.height / 2 ) - pos.y, 0 ) - Vector3.zero;
	float rot = Vector3.Angle( Vector3.up, newVector ) * ( -Mathf.Sign(x) );
	trans.rotation = Quaternion.Euler( 0, 0, rot );
	sprite.Transform();
	DefaultSpriteUI.UpdatePositions();
}

I have spent 16 hours for getting the nob work correctly, but unable to get the nob work correctly.

could anyone help me to get it work correctly.

or

any other idea to give help to the player about his direction or any resource to do it.

thanks in advance

unityboy

Here’s a simple little compass scene,
Probably not be what you want as it uses objects instead of sprites and Jscript but it might work?
Pete

250815–9023–$compass_280.unitypackage (7.06 KB)

thanks petey it worked for me

I could not believe that it is working with a single line of code. :slight_smile:

thanks again

pete one thing with this… is that the compass in my game oftenly disappears… this happens after deployment and while development as well.

any suggestion about it.??

Hey Unityboy,

I’m not sure I can help you out without knowing a little more about your project, but I’m pretty sure that issue won’t be caused by the script since it doesn’t affect the compass’s visibility.
But if you are using a similar setup to my example, check the settings on the second (GUI) camera. That might cause things to disappear if it has the wrong settings.

Try to narrow down where the issue is coming from, (is it a camera thing? or is it that the compass object is being moved or the renderer is getting switched off?). If it happens during development, that’s better because at least you can check to see if its still there in the hierarchy window.

Hope that’s of some help!
Pete