Jump to content

Expression controller and linking, trouble


remilanza
 Share

Recommended Posts

Hi,

I'm playing around with the expression controller, but there is something i don't understand. I'll explain the problem with a simple example.

 

I have object A, B and C. On C I want an attribute that measures the distance between object A and B. So I add an expression controller to a custom attribute on C. I make 2 vector variables, PosA (connected to the postion of A) and PosB (position to B). In the expression I write "length(PosA-PosB)".

So now, when I move A and B, my attribute shows me the distance between the two objects.

BUT, if I link object A to a new object, and move this new object to move object A, the value on my distance attribute doesn't change!

Is there a way around this problem?

What happens to the "position value" of an object when it's linked to another object?

(I've had similar problems when wiring something in wire parameteres, to an object that is linked to another object).

Hope you understand me.

 

Thanks in advance

Edited by remilanza
Link to comment
Share on other sites

It makes semi-sense that your A object won't read a distance once it's linked. Think about your chain of events here. Your A object is now a child to the new object. In the sense of Max math, it's only moving the parent. You need to read the distance between your parent object and your B object and you should start to see the value move. In simple terms, read the position of the parent not the child in the link.

 

Expressions are pretty literal in their functions.

Link to comment
Share on other sites

Thanks, yes I understand. But in my case the distance from the parent would not help me.

But I guess if an object is moved by another object threw wire parametering and not linking, the position of the object will still be the "real" position.

So I guess I can make it work that way.

Link to comment
Share on other sites

The easiest way to get coords in world space is getting the obj.pos or obj.transform. pos directly - you have to switch to script controller instead of expression controller and add the obj there. In some cases you can also throw in Expose TM helper instead to make things easier ;) Adding wiring just to fix this is unnecessary and only adds another level of complexity, IMHO.

Link to comment
Share on other sites

Basically, expression controllers are the oldest implementation, back before MAXScript was a part of the package, and are much faster than anything that uses MAXScript syntax (such as wire controllers or script controllers). However, they also have only a limited set of functions (and are also case sensitive) and you cannot make a scene object a variable and access its properties. For example, in script controller you can assign some object to obj variable and get its world position via obj.transform.pos or its position in parent space via obj.iNode.posInParent, and do advanced matrix transformations, access scene globals and so on. obj.transform.pos is generally safer as obj.transform computes a transformation matrix which includes ALL transforms including constraints. obj.pos should be okay provided you don't use constraints on the node, it functions as a direct property access, so $.pos.z += 10 will change node position, $.transform.pos.z will on the other hand only operate on the returned matrix so in order for it to work you'd have to do something like:

 

nodeTM = obj.transform -- get it
nodeTM.pos.z += 10 -- change it
obj.transform = nodeTM -- set it

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...