0
\$\begingroup\$

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; radarDot[i].setActive(true); } else { radarDot[i].setActive(false); } 

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

\$\endgroup\$
0

1 Answer 1

4
\$\begingroup\$

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); 
\$\endgroup\$
2
  • \$\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\$ Commented Sep 24, 2015 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\$ Commented Sep 25, 2015 at 13:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.