Hello everyone. I have attached a package with a simple scene in the hope that someone might be able to help.
Problem One: I have a map with a number of points of interest (England, Sumatra, African Cape). When a point of interest is clicked, the camera performs a SmoothLookAt towards it and the compass should rotate accordingly.
Problem Two: The compass in the bottom right of the screen is rotatable and the camera should rotate accordingly with it. However, at the moment the rotation seems to be reversed. If I turn the compass Northwards the Map rotates Southwards?
Can anyone help? And maybe make the navigation a little more predictable.
Thanks in advance!
244608–8801–$compass_830.unitypackage (495 KB)
Your package does not import correctly, at least on my end – it hangs on the compass.mb – try exporting this as an FBX file and create a new package (removing the compass.mb before building it).
Sorry, Harmit
Here is the updated package. I hope it works. Any help is appreciated.
All the best.
244736–8810–$compass_117.unitypackage (496 KB)
Without going to deep into it (I attended to immediate errors) – I had to reimport the standard asset package since the Smooth Lookat script was screaming a few errors at me.
Second – I changed your OnMouseDown since nothing was configured to receive the SmoothLookAt message, so I changed it to:
// the target must be a transform, not a game object
// possibly 'this' transform -- lets try it?
Camera.main.GetComponent("SmoothLookAt).target = transform;
Let’s go through it one problem at a time. See if this helps any and let me know.
Note – If you still need to load the variable ‘target’ in this script, you may want to change the name to something other than a reserved word (like theTarget). It is good practice to never use reserved words as variable or function names.
Hi Harmit
Strange, I’m not getting any errors when I run the project. Admittedly the SmoothLookAt script has been modified a little. But with your correction:
Camera.main.GetComponent("SmoothLookAt).target = transform;
It doesn’t update the SmoothLookAt at all.
This is the modified SmoothLookAt I got from an answer to a previous forum request and it sets the target to transform. Plus stops the LookAt at the end.
#pragma strict
var target : Transform;
var damping : float = 6.0;
var smooth : boolean = true;
private var lookingAtTarget : boolean = false;
@AddComponentMenu("Camera-Control/Smooth Look At")
partial class SmoothLookAt { }
function CameraLookAt(t:GameObject) {
target = t.transform;
lookingAtTarget = false;
UpdateLookAt();
}
function UpdateLookAt () {
if (target !lookingAtTarget)
{
if (smooth)
{
while (!lookingAtTarget)
{
var relativePos = target.position - transform.position;
var rotation = Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
var angle = Vector3.Angle(relativePos, transform.forward);
if (angle < 1.0) lookingAtTarget = true;
yield new WaitForFixedUpdate();
}
}
else
{
// Just lookat
transform.LookAt(target);
lookingAtTarget = true;
}
}
}
The problem as I see it, is how to make the compass point in the right direction. At the moment it is reversing direction, so if I turn it north, the camera turns north, but by doing that the objects which the camera is looking at turn south.
Ultimately I would like to have a compass gizmo, like the axis cube in the top right of the editor. So if I click on SOUTH, it would be like clicking on the Z or X axis on the cube and the view would rotate to face the scene from the south.
Sorry for the delay – I’m trying to work out my own issues in Unity and got caught up between that and work.
Anyway - It was because I imported the standard assets is why I couldn’t see the the CameraLookAt function it was calling.
The problem with the compass is it’s facing down just like the camera is – you want it to face up (not down). This is why it’s turning in the opposite way. Now, I had to put everything back together because the compass was not actually in the scene (not the mesh anyway). So I’m hoping I did that right. But from what I can see, it’s all about the Axis’s right now.
Let me know if this isn’t it.
[edit]: Keep in mind I am not dissecting everything, I’m browsing through and taking educated guesses. The problem is related to the axis which is usually a problem when importing from 3D apps like Maya and 3DS Max since they use different axis than Unity. Keep this in mind when debugging and make sure you know where the axis points were that the object was compiled with.