Moving Target Circle

Ok, this is going to be hard to explain without the visuals but I’l try. I started off wanting to have a GUI target picture in the middle of my screen (The target I use to aim my bullet at). Now I’ve decided I want something that is like the 2d circle which surrounds the cursor here:

As you can see that as the cursor moves across the object, the circle rotates and moves around the object. How will I be able to have a target in my game which is like that when you look around? It would be very cool. I’m not so sure if I’m explaining it correctly. I hope you can understand and can figure out an answer.

Try this :

#pragma strict

public var indicatorObject : Transform;

private var currNormal : Vector3 = -Vector3.forward;

function Update() 
{
	var mouseRay : Ray = Camera.main.ScreenPointToRay( Vector3( Screen.width * 0.5, Screen.height * 0.5, 0.0 ) );
	
	var rayHit : RaycastHit;
	
	if ( Physics.Raycast( mouseRay, rayHit, 1000.0 ) )
	{
		// currNormal smoothly follow the terrain normal :
		currNormal = Vector3.Lerp( currNormal, rayHit.normal, 4.0 * Time.deltaTime );
		
		// calculate rotation to follow currNormal :
		var grndTilt : Quaternion = Quaternion.FromToRotation( -Vector3.forward, currNormal );
		
		// rotate indicatorObject
		indicatorObject.rotation = grndTilt;
	}
}

If you know what Raycasts are, it’s fairly easy. Make a Plane with a transparent texture on it. Every frame, cast a ray from the mouse’s position and set the plane’s position to the hit.point and its rotation to hit.normal.

If you don’t know much about Raycasts, definitely find some tutorials about them, as they are invaluable in 3D games.