Drawing a destination on a minimap

Ok, so I’m writing some minimap code, and I’m having an issue. I’ve got the code to draw a dot on the map as long as the dot is close enough that it’s actually within the view of the minimap itself. What I’d like to do, though, is make it so that if you walk too far away from your objective, and it would fall off the edge of the minimap, that the dot instead just gets stuck at the edge of the circle and simply rotates around you to show you what direction to go to get to it. Here’s the code I’ve got so far for the dot when it’s close. Any ideas?

for (var ObjectiveHigh : GameObject in HighObjectives)  { 
	//find location
	var objPos = camera.WorldToScreenPoint(objective.transform.position);
	//is the objective visible on the map?
	//TODO OPTIMIZATION check on computational cost of Vector3.Distance. Square roots are usually expensive. Would Vector2 work (and be cheaper)?
	dist = Vector3.Distance(objective.transform.position, playerTransform.position);
	if (dist < 170){//this is roughly the size of the minimap
		//draw icon
		GUI.DrawTexture(Rect(objPos.x - 25,Screen.height - objPos.y - 25,50,50),objectiveIcon);
	}
	else if (dist > 170){
           //This is the area I need help with
	}

4 Answers

4

Depends on how your minimap looks, the simple solution logic is to create a line between player and target position which will intersect with the minimap boundaries once you know this intersection draw your dot there.

Hello Kulahna

I have the same problem.
Do you have now a soloution for this problem?

You could have a pre-created minimap that you show instead of a camera.

This question is nearly a year old ! =] The OP is looking for a way to show the placeDot on the minimap only to a certain range, then when past that range the placeDot stays on the outer limits of the minimap, without moving further away.

Hi there.

We have developed the KGFMapSystem. We are using a circle around the player to determine if the marker should be visible. If the marker leaves the circle it is replaced by an arrow at the border of the minimap which is pointing in the direction of the marker. Checkout the demo here.