I am making a radar script in a unity FPS game project I am making for class. I already have a working example of a radar script that works in relation to the player's position. However the rotation is in relation within the world map, not the player's view.

In code I have it kinda like this (not actually my code, as I don't have it with me right now, but basically the same algorithm)

if (isPlayerInViewRange(otherPlayer[i]){
    //these are both normalized Vector
    dir = getDirectionFromPosition(player, otherPlayer);
    dir = rotateDirectionInRelationshipToPlayer(player, dir); //problem here
    dir = new Vector3(dir.x, dir.z, 0);

    dir.Scale(MapToRadarPosition, 0, MapToRadarPosition);
    radarDot[i] = dir;
} else {

Any ideas what I am missing, I feel like I am missing some obvious function to do it.

| improve this question | | | | |

Use Transform.TransformDirection() method where Transform is your player transform.

// Calculate the x-axis relative to the camera
camera = Camera.main.transform;
cameraRelativeRight = camera.TransformDirection (Vector3.right);
// Apply a force relative to the camera's x-axis
rigidbody.AddForce (cameraRelativeRight * 10);
| improve this answer | | | | |
  • \$\begingroup\$ I am not using any sort of Camera. Its basically kind of like a halo style radar. Its a simple green circle with white dots indicating players. I am working with Vector3s Directory. \$\endgroup\$ – needoriginalname Sep 24 '15 at 14:31
  • \$\begingroup\$ Blue kindly edited my post with example from Unity documentation, which uses Camera transform for instance. But I advised you using player's Transform. In your code simply refer to this.transform.TransformDirection(dir) \$\endgroup\$ – Skyblade Sep 25 '15 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.