- Home /
Modify distance with var?
Hello guys, well I have been dealing with this all day and I can not get it working... I wrote a script to orbit the camera around my character, everything works as expected. I have not defined the min and max zoom allowed on the player but I will use mathf.Clamp.. To do that First: I am going to need a var on the inspector that modifies the "distance". What ive got now is:
var dst: float;
function Update(){ dst = Vector3.Distance (target.position,transform.position); }
But this var only reads the distance (cant modify it), how can I create one that can be modified via inspector, I know it is something simple but I have not found the answer.
Thanks for your time.
note that Unity give you an orbit script, for free!!!!
it INCLUDES a public "distance" variable. so your work is done.
it is right there included in your download. just find it and use it. it is very easy to modify.
I already tried that but it creates other problems with my script.
then there's something else wrong with your script, Noah.
just use the unity-supplied "orbit" script.
it works completely separately from everything else, and will not, in any way whatsoever, affect your own scripts!
hope it helps!
Answer by kolban · Apr 28, 2012 at 03:48 AM
If I understand what you are looking for, you wish to get a position (P) for a camera (C) that is a fixed distance (D) from a game object (G). The way I would do this would be to determine the vector that would be G.position - C.position ... call this V1. Then I would normalize this vector so it has unit length ... call this V2. Next I would multiply V2 * D which would give me a vector from G to P. And thus to calculate P, the answer would be G.position + V2.