I’ve loaded a series of 3d spheres, with panoramas mapped onto them… and am attempting to create a panorama-node interface similar to that found in Return to Mysterious Island, Myst III Exile, Myst IV, Schizm, or a high-end QTVR tour.
Basically, I’ve had a ton of trouble figuring out how to achieve even basic navigation. I’m a good artist but a terrible programmer.
I started with the camera inside Sphere 1, in the center. I applied the “Mouse Look” script.
I am trying to develop a navigation script to apply to the camera, which will, essentially, check whether there’s been a click, and if so, what node the camera is inside, and what direction the camera is facing along the Y axis… to determine if the camera should move to another node.
Here’s the code I’ve got so far, and it’s not working:
function Update () {
if(Input.GetMouseButtonDown(0) == 1) // if click happens
{
if(transform.position.x == 0) // if camera is in center of Sphere 1
{
if(transform.eulerAngles.y > 20 transform.eulerAngles.y < 50) // if rotation along y axis is between two numbers
{
transform.Translate(700, 0, 0); // Move camera to center of Sphere 2.
}
}
}
}
What do I do with this to make it work?
Kind of depends on why it isn’t working now
Checking if ‘transform.position.x == 0’ is suspect though; is Sphere 1 at zero on X? Even if it is (and the camera is too), floating point numbers have a margin of error, so it’s always safer to say something like ‘is v1 < 0.01 and > -0.01’ (where 0.01 is some small value). Similarly, the problem could just be that the camera’s euler angles aren’t what you think they are, invalidating that part of your tests.
In this case, your best bet is to use Debug.Log() to print out the values you’re testing and see which tests are passing or failing. Then you’ll have concrete numbers to compare against your expectations and will know exactly where things are going wrong.
Yes, the camera is at zero on X, but I made a modification as you suggested anyway.
It turned out while doing debug logs (thanks for that advice) that the problem was earlier in the code…
replacing “1” with “true” solved the problem.
Anyway, thanks for your help!
Okay, next question:
What code would I use if I wanted to shift the camera view to a particular angle, either instantly, or over the course of a half-second?
There are plenty of ways to set the rotation instantly, any of which can be used to change it over time (by making incremental changes), The various lerp functions are also very useful for interpolated rotation over time; take a look at Quaternion.Lerp() / Quaternion.Slerp() for example.