- Home /
Minimap player dot
Hey,
How to make the player as dot on your minimap?
Here is the code without dot:
var target : Transform;
var damping = 6.0;
var smooth = true;
function LateUpdate () {
if (target) {
if (smooth)
{
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
else
{
// Just lookat
transform.LookAt(target);
}
transform.position.y = target.position.y + 90;
transform.position.x = target.position.x;
transform.position.z = target.position.z;
}
}
function Start () {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
Answer by DerWoDaSo · Jul 04, 2012 at 03:42 PM
I guess this script is attached to a camera, which renders the scene from above?
A simple solution might be to create a big dot-like object (like a sphere or better simpler) and attach it to your player (a little bit above maybe). Then set the layer and the culling mask for the minimap camera and the main camera accordingly, so that the "dot" is only rendered on the map.
EDIT:
Of course there are several possible solutions for this. But they depend on how you setup your minimap...
Is it a camera which is rendering the whole scene from above?
Is it an image of the level which is displayed centered around the player?
Last time I created a minimap, I used NGUI to show an image (editied screenshot of the scene from above) with little sprite icons (dots, arrows) for different items on the map.
Answer by marcfielding · Feb 18, 2014 at 12:12 PM
Yep!
Two ways I can think of:
1) Use SphereCast (docs are pretty straight forward) to locate each player from the camera above and then place a gui element on that camera for each player
OR
2) Create an array of gameobjects (players or NPC's etc) and have a script attached to the minimap camera, then simply wizz through it grab their positions and add Gui elements for the minimap to represent their position.
I'd imagine you don't want everything appearing on the minimap all the time(ie you want radar type effects) so either of these would work well, i'm not sure on how expensive SphereCasting is in terms of processing power.
EDIT I've just re-read you question, sorry i've just woken up! If its JUST the player you want then attach a script to your minimap camera and in the Start() function store a reference to your players gameobject.
Then in update simply add a gui element(your dot) to the present position of the player!
If you need more clarification let me know and i'll be happy to help!
Good Luck!
Marc
[1]: https://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html
The "Edit" solution will work fine of course, but I would do 'FindObjectWithTag("Player")' once in Start() and store a reference to it. If your player changes, just nofity the $$anonymous$$imap script. :)
Yeah good catch DerWoDaSo edited accordingly, thanks!
Answer by KhShani · Feb 18, 2014 at 09:14 AM
the above solution worked but but is there is another solution for this ????
I edited my answer above. There are many possible solutions for this problem. $$anonymous$$y initial answer was just the most simple one, which came to my $$anonymous$$d at that moment. ;)