- Home /
Creating a simple mini-map?
I'm trying to create a simple mini-map for my latest project, but can't seem to get it to work entirely.
I've already created the camera, and all settings are right (depth, layer etc), so it already looks like a mini-map. The camera will follow the player on the x and z axes (not the y), but I can't get it to rotate properly... I want the camera to always look at the terrain from above, of course. Also note that the player controls an airplane that can adjust its pitch, and can also fly upside-down if rotated enough.
I'm currently using this code for the mini-map camera:
#pragma strict
var minimapTarget : Transform;
var smooth : float = 3;
function Start () {
}
function Update () {
transform.position.x = Mathf.Lerp( transform.position.x, minimapTarget.position.x, Time.deltaTime*smooth );
transform.position.z = Mathf.Lerp( transform.position.z, minimapTarget.position.z, Time.deltaTime*smooth );
}
How can I get this to rotate with the player?
Answer by HolBol · Nov 14, 2012 at 12:15 AM
Why not set the camera's transform.rotation.z to be equal to the target's? That could work.
hmm, probably the y, I think, rather than z.. You COULD simply add this line:
transform.rotation.eulerAngles.y = $$anonymous$$imapTarget.rotation.eulerAngles.y;
that WOULD work, UNLESS the object goes upside down..
which we know it might.. SO it's a bit more complicated..
Good point, I did mean Y. That's what too.much time in blender does to you.
Answer by m4s4m0r1 · Nov 14, 2012 at 12:33 AM
Create new Camera and Set this Script to your new Camera
var target : Transform;
var distance : float;
var height : float;
var damping :float;
var rotDamp : float;
function LateUpdate () {
var wantedPosition = target.TransformPoint(0,height,-distance);
transform.position = Vector3.Lerp(transform.position,wantedPosition,Time.deltaTime*damping);
var wantedRotation = Quaternion.LookRotation(target.position - transform.position,target.up);
transform.rotation = Quaternion.Slerp(transform.rotation,wantedRotation,Time.deltaTime*rotDamp);
}
after that, you can adjust your own setting to this camera...
Your answer
![](https://koobas.hobune.stream/wayback/20220613083825im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Quaternion Slerp Sanity Check 1 Answer
How to freeze the rotation or the position on the camera transform? 1 Answer
how do i make first person character rotate left and right along with camera? 0 Answers
Override Oculus Orientation 5.3 1 Answer
How to make the camera rotate only when right click is held down on the mouse? 1 Answer