HeadLookController Improved.

This is profiler diagramme from Head Look demo project (from www.unity3d.com) (1 character and one script)

The dark-red picks is a Garbage Collector work. When your application work in browser, this time for garbage collecting very grows.

This is my improved variant (3 characters in one time and three scripts in work) (other project)
As you see, no garbage collecting at all.

This is online demo : http://www.unity3d.ru/composition/radsim/testAnim.html

Cheers.

315348–11132–$headlookcontrollerimproved_188.cs (7.9 KB)

Hey, cool characters :o

verry nice keep it up! :wink:

:sweat_smile:
Ha-ha! My error. Dark red peaks go from GUI. (and I’m a stupid moose)
But, nevertheless, I have a little bit accelerated this script. :lol:
(reloaded)

the script doesnt work, i get the following error when trying to add it to my character:

Cant add script.
cant add script behaviour headlookcontrollerimproved. the scripts filename doesnt match the name of the class defined in the script!

would be great if this could be fixed! :smile:

Changle the script name to HeadLookControllerImproved.cs

would it be possible for you to provide the example scene?
would be nice to see how you setup the scene/characters

changing the name did the trick (tried that myself also, but i guess i missed a typo).

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.

my interest in your scene is mostly because of the npc’s
having them play animations when the user is at a certain range.

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.

Beautiful work, thank you for sharing this!

Will, the speedup is not too much. In general this is not my victory.
:roll:

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.

Ok, soon I’ll create the demo of range detection for new Antares release, like this one.

Cant add script too.:

Assets/CS/headlookcontrollerimproved_188.cs(6,14): error CS0101: The namespace global::' already contains a definition for BendingSegment’

Cant add script too.:

Assets/CS/headlookcontrollerimproved_188.cs(6,14): error CS0101: The namespace global::' already contains a definition for BendingSegment’

Please, rename your file to HeadLookControllerImproved.cs

Hi Neodrop,

There seems to be a bug(?) in your improved version,

in line 100:

for (int i=0; i<_nonAffectedJointsLength; i++) {
	jointDirections[i] = nonAffectedJoints[i].joint.position - nonAffectedJoints[i].joint.position;
}

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.

Thank you for your sharp eye.