I’m developing a 3d navigable Villa Of Oplontis, the largest and best preserved example of the Roman Villa close to Pompei (Italy).
I have a problem creating a small minimap.I tired two solutions without success:
1 RADAR SCRIPT
I have seen the radar script in the wiki, but is not working. I cannot see the bleeping and the map scale is not working.
2 Minimap
I created another camera (ortho) which visualize a texture of the Villa’s plan and a little arrow that locate the player. The map should be still,the arrows and the camera will move following the player movements. I want to replicate only the x and y movements, so i cannot parent everything to my character. How should i do that?
Thanks
In the script for your map camera, you could possibly refer to the x and z movement of your character object, and set your map camera’s position based on that.
do you have a precompiled script? a tutorial? i tried two days without success…
post what you have so we can suggest options to solve it
using UnityEngine;
using System.Collections;
public class arrow: MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
// initialise variables
Vector3 playerPos = Vector3.zero; // vector to hold our player position
Vector3 newCamPos = Vector3.zero; // vector to hold our new camera position we’ll make
// horrible stuff goes here
GameObject player = GameObject.FindWithTag(“Player”); // Find the gameobject we’ve tagged as Player and store it in player variable
playerPos = player.transform.position; // playerPos vector now holds the position of the player gameobject
newCamPos = new Vector3(playerPos.x , 0 , 0); // newCamPos now holds out edited vector for the camera
transform.position = newCamPos; // We’ve put the edited vector onto the proper camera now - done!
}
}
most obvious error is that you don’t set the z coordinate of the radar cam, only x
the other problem is that you don’t set the y position of the cam relativ above the head of the player, for example
and the last problem is that you don’t tell the cam to target the player but thats something you potentially do somewhere else
newCamPos = new Vector3( playerPos.x, playerPos.y + 200, playerPos.z)
could you explain me what you mean?
thanks a lot, you are very helpful
i’m getting mad working around this minimap.
another question: my plane with the background map is far from the model, thus i cannot see it when i’m outside the villa.
My concern is how to use my player coordinates position and replicate them on my map camera
i adapted this form wiki
@script ExecuteInEditMode()
// No hay que olvidar colocar una etiqueta "Cow" al objeto vacio asignado como radar
// y una etiqueta "Enemy" a todo aquello que quieras que aparezca en rojo
// posteriormente agregaremos objetos en otros colores
//define las texturas a usar
public var blip : Texture;
public var amigo : Texture;
public var radarBG : Texture;
//define los objetos
public var centerObject : Transform;
public var mapScale = 0.3;
public var mapCenter = Vector2(50,50);
function OnGUI () {
//Deshabilita el siguiente comentario y esto permitirá escalar el radar automáticamente a la pantalla.
//GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 600.0, Screen.height / 450.0, 1));
//Dibuja el radar, identificado como "centerObject"
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
GUI.DrawTexture(Rect(mapCenter.x-50,mapCenter.y-50,100,100),radarBG);
// Muestra a los enemigos
DrawBlipsForEnemies();
DrawBlipsForFriends();
}
function DrawBlipsForCows(){
// Localica a todos los objetos que tengan la etiqueta "Cow"
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Cow");
var distance = Mathf.Infinity;
var position = transform.position;
// Los muestra en pantalla
for (var go : GameObject in gos) {
drawBlip(go,blip);
}
}
function drawBlip(go,aTexture){
centerPos=centerObject.position;
extPos=go.transform.position;
// Primero necesitamos conseguir la distancia entre el enemigo al personaje
dist=Vector3.Distance(centerPos,extPos);
dx=centerPos.x-extPos.x; // Que tan lejos está el enemigo del personaje lateralmente?
dz=centerPos.z-extPos.z; // Que tan lejos está el enemigo del personaje frontalmente?
// cual es el angulo hacia el que esta el enemigo, compensando el ángulo del personaje?
deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
// hace el calculo para encontrar la posicion del enemigo en x, y para dar el angulo
bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
bX=bX*mapScale; // escala la cordenada X para mostrarla en el radar
bY=bY*mapScale; // escala la cordenada Y para mostrarla en el radar
if(dist<=150){
// Este es el diámetro de nuestro punto en el radar
GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,3,3),aTexture);
}
}
function DrawBlipsForEnemies(){
// Encuentra todos los objetos etiquetados como "Enemy"
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Enemy");
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and call drawBlip function
for (var go : GameObject in gos) {
drawBlip(go,blip);
}
}
function DrawBlipsForFriends(){
// Encuentra todos los objetos etiquetados como "Amigo"
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Amigo");
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and call drawBlip function
for (var go : GameObject in gos) {
drawBlip(go,amigo);
}
}
I created the radar background, a blue point and a red point…
the red point is directed to Enemy and the blue to “Amigo” (Friend)
Sorry, buy the comments in the code are in spanish so i can make diference between code and hide comments