[Closed] Look at with script controller
I would like to do a look at constraint but only in one or two axis. Any idea how to do this with script controller?
Thanks.
Ok, this is not the exact code you need for the script controller itself but the code needed for a node to look at another node.
-- References to the used nodes
source = $Cone01
target = $Dummy01
-- We need the source node to look at the target node, so...
-- Calculates the vector from the source to the target (the view or look vector)
look = normalize (target.pos - source.pos)
-- Take the target's up vector as the temporal source's up vector
tempUp = target.transform.row2
-- Calculates the right vector
right = cross look tempUp
-- Calculates the source's real up vector
up = cross look right
-- Finally calculates the source's matrix transformation
source.transform = matrix3 right up look source.transform.translation
This script takes the source Z axis as the “look at” vector but you can use the same code to do the same with the other basis vectors.
To test this script, create a cone and a dummy (named Cone01 and Dummy01 respectively) and execute the script.
HTH.
Sorry, I missed a – sign on the script above. Now it works. Anyway I’ll create the controller for you to see.
Ok, I’ve created a little tool that allow you to choose the source node (the node that will receive the rotation script controller) and the target node, that is, the node where the source node will look at.
I know, the tool would be better if you could specify the look-at axis, flip options, etc. Maybe if I have the time…
By the way, to be able to access the scripted node properties (position for instance) I have used a dummy node. You know, for some reason you can’t make self references into the script controller. That’s the reason why I’ve created the dummy. Anyone knows how to access the scripted node properties without the need of this “trick”?.
Oh, I’ve have attached the code and a video that shows how to make use of this little tool.
De nada!.
PD: Oops, no rar files allowed.
The best would be to have a swivel angle target options, and option to limite the axis.
I am looking systems to do facial animation via bones. I can makes control point. Assign bones to those point. Those point control the bones orientation ans scale using lookat and positions constraint. But the problem is; when you rotates the head, the bones maintains their x axis, because they have not a option to pick a swivel angle target like when you have a IK chain. So Iam trying to do my own bones with boxes. I have make a script controller to control the box heigth calculating distance between the source and the target.
With your script controller I have the same problem yet, but thanks again. I am going to try learn more about vectors, my maths and script level is not too high (like my english :)). If you can help me more, perfect but if you haen´t the time doný worry. And don´t worry about the dummy, it will be the control object.
Thanks again:buttrock:
i would like to write a script which can simulate reflection of rays from concave miror.
I couldnt find a tool which would mirror the line along choosen axis.
with look at constraints i could find normals or tangents.(They would be used for mirroring)
Anybody knows to slove that it would be nice!
thx in advance:)