Well, it is just the same file from original Head Loock demo from www.unity3d.com
Nothing especial. You can download this demo and use my variant of the script instead original one.
There is used a part from next Antares release (Zone Range component) for check wether the object coming in control area.
In this demo this is a simple ring (Distance check). If main object (in this case this is a Camera.main) is enter close than 5 meters, character play reaction and activate HeadLook.
Simple task.
But, sorry, this is a commercial projects models and I can’t share this demo.
kinda off topic, but i’ve been trying to make a script like yours. but failing at getting it working properly. mostly the range finding in combination with enabling the headlook/animation.
The same position subtract itself? That doesn’t look right…
Following is the original code:
for (int i=0; i<nonAffectedJoints.Length; i++) {
foreach (Transform child in nonAffectedJoints[i].joint) {
jointDirections[i] = child.position - nonAffectedJoints[i].joint.position;
break;
}
}
The nested foreach loop is just to obtain the first child of the joint, since it break the loop at the first iteration. So in the original code it’s the position of the child joint subtract the parent’s. (I haven’t tried HLC yet, so don’t mind me if I am wrong)
BTW, I think moving all the floats from local arguments to class members probably isn’t that great because primitive type allocated in stack (local argument) should be better than in heap (class member).
May be you right. But this code works properly. Atleast for me. But I’ll look at it.
In general that premises of a writing of this variant have appeared false - as I have written above, GC problems arose from GUI instead of from a code.
May be, in some future, I’ll write the Editor window for visual customisation of this script also I will possibly not change an initial code. Unless - I will remove “foreach” cycles because I do not love their productivity. May be a little else. I’m not sure.