I need that my camera looks at the average of the position of 4 objects in my level so I have defined 4 Transforms like this( for the 4 objects):
var target1 : Transform;
var target2 : Transform;
var target3 : Transform;
var target4 : Transform;
I want my camera to looks at my target variable so i have defined it as private :
private var target : Transform;
Now I need to calculate the average position:
target =(target1 + target2 + target3 + target4)/4; But I am new with vectors , transforms and positions in Unity so I need some help. I’ve tried of calculate the average of the x,y and z coordenates of the transforms but nothing.
Some advice?
Htwarrior
Use i.e. target1.position instead of just target1.
target1 and friends you have defined as Transform. Check out the members of that class.
-Jon
I’ve tried it, but I realized that you can 't modify target.position in that way (Unity throws an error) so I tried this and it worked:
var target1 : Transform;
var target2 : Transform;
var target3 : Transform;
var target4 : Transform;
private var aPosition : Vector3;
aPosition = (target1.position + target2.position +target3.position + target4.position)/4;
And then by using the aPosition variable instead of the target variable in the SmoothFollow.js script I had what I wanted. BTW I set the wantedRotationAngle variable to a constant.
Thanks anyway
HTwarrior
You definately can modify the position of a transform. It seems target is not declared in your script though, maybe you need to use target1.position instead of target.position.