action / enemy lock on reticle

Hi,

I need to make a (for lack of a better term) “action reticle”.

Examples:
This kind of thing is used in a lot of PS2 games, where you can “lock on” to an enemy, often a ring with enemy health displayed etc. Or you hop on an elevator and a reticle pops up around the button, showing that you need to hit the action button to activate the elevator.

How is this best done in Unity?

I have a tank (that holds liquids, not bullets) with a control panel. I need to indicate to the player when they get close, that they need to click a button on the control panel.

I’m not asking you to do it for me, just point me in the right direction something like “make a layer, put a plane in that layer, attach a texture to the plane, set the alpha etc.”

For reference, I’m a programmer, a newbie at 3D and not at all a modeler or an artist.

Somewhere on this forum is a link to vehiclesexamples.zip, and theres a script in there that does that. Have a search

HTH
AC

Probably I’d use a GUITexture with the coordinates derived from WorldToViewportPoint (and use a trigger to activate it).

–Eric

If I try vehiclesexamples.zip it brings up everything with a zip file mentioned in it. If I try vehiclesexamples (minus the .zip part) I get just this post :(. A google search for vehiclesexamples.zip turns up nothin’

Thanks, though for trying.

I was wondering about using a GUITexture for this. I’ll have to look up WorldToViewportPoint. I’m still so new at this.

Its either this one:

var crosshair : GUITexture;

function Update () {
	if(crosshair)
	{
		var hit : RaycastHit;
		if(Physics.Raycast(transform.position,transform.forward,hit))
			crosshair.transform.position=camera.main.WorldToViewportPoint(hit.point);
		else
			crosshair.transform.position=camera.main.WorldToViewportPoint(transform.position+transform.forward*1000);
	}
			
}

or this one

var crosshair : GUITexture;
var maxTargetDistance = 1000.0;

function Update () {
	if(crosshair)
	{
		var target : GameObject;
		
		maxProximity = -1.0; 
		for(go in gameObject.FindGameObjectsWithTag("MissileTarget"))
		{
			difference = (go.transform.position-transform.position);
			distance = difference.magnitude;
			if(distance > 1) //don't aim at ourselves!
			{
				proximity = Vector3.Dot(difference.normalized,transform.forward)-distance/maxTargetDistance;
				if(proximity > maxProximity)
				{
					target = go;
					maxProximity = proximity;
				}
			}
		}
		if(target)
			crosshair.transform.position=camera.main.WorldToViewportPoint(target.transform.position);
		else
			crosshair.transform.position=Vector3(-1000,-1000,-1000);			
	}
			
}

Joachim wrote these I believe, I cant say if they work with Unity2.

HTH
AC

Thanks!
This is a lot closer than I was yesterday to getting it to work.

OK the bottom script does closer to what I want. I can modify / tweak and get to where I want now, I think.

Thanks, again Targos!

Side Note: You folks are awesome, this is an absolutely awesome forum for someone learning a product like Unity and I have been on a few product forums in my life…