Credit for this Radar Resource rightfully go to Pedrodx, But there are still a few of my lines mixed in there
I added a couple lines to disable the radar return sprite when it leaves the boundary of the radar base sprite..
This radar gives impressive results, but the user needs to keep in mind that a few things will need to be adjusted for this to work properly in your Project:
The Values of returnx and returny will need to be changed to correspond to the screen location of your base sprite, these floats coordinate the player object and the radar base sprite as relative center points...
scaleFactor should be changed depending on your world size....
The last two lines of code turn off the radar return sprite when it leaves the boundary of the radar base sprite... This will have to be tweaked according to the size of your world...( a hint to help out with this is to attach the relativeLocation.z to a value print object to determine the proper setting)
I added a couple lines to disable the radar return sprite when it leaves the boundary of the radar base sprite..
This radar gives impressive results, but the user needs to keep in mind that a few things will need to be adjusted for this to work properly in your Project:
The Values of returnx and returny will need to be changed to correspond to the screen location of your base sprite, these floats coordinate the player object and the radar base sprite as relative center points...
scaleFactor should be changed depending on your world size....
The last two lines of code turn off the radar return sprite when it leaves the boundary of the radar base sprite... This will have to be tweaked according to the size of your world...( a hint to help out with this is to attach the relativeLocation.z to a value print object to determine the proper setting)
Quote
//
// Pedrodx's Radar Script
// This script is intended to allow
// Radar Functionality
//OBJ_22= player object
//OBJ_0= Target Object
//OBJ_44= Radar Return Sprite
//
Vector3 crossProduct(Vector3 v1, Vector3 v2) {
Vector3 v;
v.x = v1.y * v2.z - v1.z * v2.y;
v.y = v1.z * v2.x - v1.x * v2.z;
v.z = v1.x * v2.y - v1.y * v2.x;
return v;
}
Vector3 radarReturn;
Vector3 playerLocation;
Vector3 targetLocation;
Vector3 relativeLocation;
Quaternion playerOrientation;
Quaternion spriteOrientation;
float x;
float y;
float z;
//the center x and y coords of the radar return (from Sprite)
const float returnx = -11.35f; // H coord of Base sprite
const float returny = -8.15f; // Y coord of Base sprite
const float scaleFactor = 25; //Change this value to scale the radar to your world size...
void Main ()
{
iObjectOrientation(OBJ_22, playerOrientation);
iObjectLocation(OBJ_0,targetLocation); //get target location
iObjectLocation(OBJ_22,playerLocation); //get player location
relativeLocation.x=targetLocation.x - playerLocation.x;
relativeLocation.y=0;
relativeLocation.z=targetLocation.z - playerLocation.z;
//check out for target left or right relative to the player
Vector3 playerRotationZ;
iVectorRotate(playerRotationZ, Vector3(0, 0, 1), playerOrientation);
//desconsider the camera pitch
playerRotationZ.y = 0;
//new: normalizes the playerRotation vector... fuzzy logic...
float przLength = iVectorLength(playerRotationZ);
if (przLength > 0)
playerRotationZ /= przLength;
Vector3 cpLR = crossProduct(playerRotationZ, relativeLocation);
OUT_66 = cpLR.x;
OUT_88 = cpLR.y;
OUT_110 = cpLR.z;
//check out for target front or behind relative to the player
Vector3 playerRotationX;
iVectorRotate(playerRotationX, Vector3(1, 0, 0), playerOrientation);
//desconsider the camera pitch
playerRotationX.y = 0;
//new: normalizes the playerRotation vector... fuzzy logic...
float prxLength = iVectorLength(playerRotationX);
if (prxLength > 0)
playerRotationX /= prxLength;
Vector3 cpFB = crossProduct(playerRotationX, relativeLocation);
//cpXX is as if it was a "distance" value...
radarReturn.x = returnx + cpLR.y / scaleFactor;
radarReturn.y = returny - cpFB.y / scaleFactor;
iObjectLocationSet(OBJ_44,radarReturn); //set radar return location
if (relativeLocation.z > 90) OUT_44 = 0;///These two lines turn off the Radar Return when It leave the boundaries of the Base Sprite
else (OUT_44=1);
}