- Home /
invert radar axis
Hi all, I'm using a radar version from unify wich works perfectly. It draws blips for objects around you by their tags as if you look the scene from above. So, objects above you in the radar are in front of you and the ones down the radar are behind you. I want it to show as if the radar is looking from behind you instead from above, so blips up in the radar are above you and down the radar are below you. Objects centered in the radar won't be in your same position but just in front of you, as it should work in an Space Game or Flight Simulator. There is the code drawing blips:
function drawBlip(go : GameObject, aTexture : Texture, iconPixels : int){
centerPos=centerObject.position;
extPos=go.transform.position;
// first we need to get the distance of the enemy from the player
var dist=Vector3.Distance(centerPos,extPos);
var dx=centerPos.x-extPos.x; // how far to the side of the player is the enemy?
var dz=centerPos.z-extPos.z; // how far in front or behind the player is the enemy?
// what's the angle to turn to face the enemy - compensating for the player's turning?
var deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
// just basic trigonometry to find the point x,y (enemy's location) given the angle deltay
bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
bX=bX*mapScale; // scales down the x-coordinate so that the plot stays within our radar
bY=bY*mapScale; // scales down the y-coordinate so that the plot stays within our radar
if(dist<=mapWidth*.5/mapScale){
// this is the diameter of our largest radar circle
if (iconPixels == iconSize) {
GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,iconSize,iconPixels),aTexture);
} else if (iconPixels == iconBig) {
GUI.DrawTexture(Rect((mapCenter.x+bX)-((iconBig-iconSize) / 2),(mapCenter.y+bY)-((iconBig-iconSize) / 2),iconBig,iconPixels),aTexture);
}
}
}
How to modify it to draw blips as I explain above? Thanks in advance!
Answer by roamcel · Jan 13, 2012 at 10:23 PM
Have you tried changing the '270' value? I really didn't try to sort out how the script works, but that number seems to be related with target positioning :D
var deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
Hi, thanks for the answer but it's not this value. I need to change the entire coordinates system, this 270 value is to keep the facing direction of the player as nord of the radar but it keeps looking at your position from above. It's nomething about the x y and z axis but I don't know how to change/combine them...
Ok let's try this one: var dz=centerPos.z-extPos.z; // how far in front or behind the player is the enemy?
turn it into
var dz=-(centerPos.z-extPos.z);
Sorry if these look as half-assed attempts, but they actually are. The script seems exceedingly complicated for its purpose, and going through it line by line is a pain.
Ok, I think I didn't explain well what kind of new functionallity I need. Changing just a line won't work and the part to change are the axis. Now the radar is looking from above and it will if any axis is changed, no mather how a line is modified. I think the key is changing the axis here:
var dx=centerPos.x-extPos.x;
var dz=centerPos.z-extPos.z;
var deltay=$$anonymous$$athf.Atan2(dx,dz)*$$anonymous$$athf.Rad2Deg - 270 - centerObject.eulerAngles.y;
This three lines tell the script how to use the x, y and z axis for an above radar and I need them to work as a behind radar. But any convination I tried didn't work as expected...
Your answer
Follow this Question
Related Questions
Navmesh or terrain axis swap from XZ to XY? 0 Answers
Objects not rotating their axis. 0 Answers
Does unity support a 16 bits axis input? 0 Answers