Third person crosshair

I’m working on a tech demo to get to grips with unity. It uses third person perspective, with the camera orbiting the player controlled by the mouse x-axis, which also controls the player rotation.

I’d also like the y-axis of the mouse to control the y-axis of the cross hair, which shouldn’t be hard, although what I’m struggling to get my head round is how I’m going to do the cross hair.

The cross hair is obviously relevant to the player model’s perspective and not the user’s. I thought about putting a cross hair model inside the Player prefab so it rotates with the player, but ideally I’d like it to either render at a pre-determined range, or draw itself on the nearest object to the player.

Any ideas what I should look into? If I included a crosshair model in with the Player, what sort of script would I need to modify the distance from the player relative to it’s surroundings?

Any advice will be much appreciated!

I think a GUITexture object would make this easier for you then trying to make a floating 3D reticle.

There are many posts on the forum covering this with examples. Here is one after a quick search for crosshair. It also comes up with a search for reticle.
http://forum.unity3d.com/viewtopic.php?t=7615&highlight=crosshair

Eric has a nice example he posted on the forum too with code.

Ricko

Typically, third person crosshairs are in no way different from first person crosshairs. (Yep, GUITextures are ideal for this.) The only thing you’d have to do differently is raycast to find out what point in 3D space the cross hair is aiming at, so you can have the third-person character shoot in the direction of that point.

–Eric

My favorite method for 3rd person crosshairs is to draw a couple planes in 3d. It makes it a bit harder to aim perfectly, but I find its kind of fun.

// put this script on the player object.
// reticles is a list of objects. each object has a reticle graphic attached or as a child of it, the center of the reticle is at the object's transform handle, and the blue axis of the object points away from the direction that the reticle should be viewed from. Create and assign these objects in the inspector.
// reticlePositions corresponds to reticles. It should have the same length as reticles, and each number in it should range from 0 to one. 1 is at the target point, and 0 is at the player.

var reticles : Transform[];
var reticlePositions : float[];
var maxRange = 1000.00;

function Update()
{
	var targetPoint : Vector3;
	var cameraTransform : Transform = Camera.main.transform;
	var hit : RaycastHit;
	if(Physics.Raycast(cameraTransform.position, cameraTransform.forward, hit, 	maxRange))
		targetPoint = hit.point;
	else
		targetPoint = cameraTransform.position + (cameraTransform.forward * maxRange);

	var rotation = Quaternion.LookRotation(targetPoint - transform.position);

	var i = 0;
	while(i < reticles.length)
	{
		reticles[i].position = Vector3.Lerp(transform.position, targetPoint, reticlePositions[i]);
		reticles[i].rotation = rotation;
		i++;
	}
}

excellent! I figured it would be pretty similar to the FPS code.

I’ll try this when I get home. Cheers guys!