PDA

View Full Version : a quick question regaurding expressions (local VS Global Axis)


brianellebracht
05-06-2003, 08:28 PM
A Quick question... When you make a statement, for example,
if Sphere.translateX = 3; is there anyway that you can make it so that it translates x on the local axis instead of the global? I have an if else expression, but i want the object to continue in the dirrection that it is rotated in if that makes any sense, like if a car were to turn or something...

So Just wondering if there was a way to make an expression control the local axis of an object instead of the global. Hope you guys can help. THanks for taking a look,

Brian Ellebracht

mark_wilkins
05-06-2003, 08:43 PM
Check out my answer in the other thread.

BTW, while translateX moves the car along its local axis (not global,) generally the origin point of its local coordinates do NOT move or rotate with the car. A motion path lets you bypass the whole issue, though...

-- Mark

brianellebracht
05-06-2003, 08:49 PM
I am checking it out now, thanks

brianellebracht
05-06-2003, 09:02 PM
I understand... I'm not using a car for an animation, that was just an example. Umm... I am just trying to figure out if this is possible, I wrote an expression for tank treads to go the right speed, and direction as the tank, depending on its speed, and if it is rotating, and then what direction it was heading. It would work if I could get the translation to work on the local axis instead of the global. When ever I rotate out of the x axis it doesn't work, then, if i add another for the z, then the idea works, but only when you are in either the x or z axis. So its allways local????

Hmmm try this...
Copy and paste this into your script editor and exicute it...

file -f -new;
select -cl;
// Result: ./untitled //
polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 1 -ch 1;
// Result: pSphere1 polySphere1 //
scale -r 4.20753 4.20753 4.20753 ;
select -cl ;
select -r pSphere1 ;
select -r pSphere1 ;
duplicate -rr;
// Result: pSphere2 //
move -r -ls -wd 0 0 14.80126 ;
select -r pSphere1 ;
expression -s "if (pSphere1.translateZ)\r\n pSphere1.translateZ;\r" -o pSphere1 -ae 1 -uc all ;
// Result: expression1 //
select -cl ;
select -r pSphere2 ;
move -r 0 5.426535 0 ;
// Undo: move -r 0 5.426535 0
move -r 0 0 1.953876 ;
// Undo: move -r 0 0 1.953876
move -r 2.005169 0 0 ;
// Undo: move -r 2.005169 0 0
select -r pSphere1 ;
move -r -48.863783 0 0 ;
// Undo: move -r -48.863783 0 0
move -r 0 0 6.91197 ;
// Undo: move -r 0 0 6.91197
// Undo: select -r pSphere1
// Undo: select -r pSphere2
// Undo: select -cl
// Undo: EEapplyCB
// Undo: select -r pSphere1
select -r pSphere1 ;
select -r pSphere2 ;
select -r pSphere1 ;
expression -s "pSphere1.translateZ=pSphere2.translateX" -o pSphere1 -ae 1 -uc all ;
// Result: expression1 //
select -r pSphere2 ;
move -r -ls -wd 0 0 -8.651584 ;
// Undo: move -r -ls -wd 0 0 -8.651584
move -r -ls -wd 0.873661 0 0 ;
select -r pSphere1 ;
rotate -r -ws 0 20.345198 0 ;
select -r pSphere2 ;
move -r 6.337721 0 0 ;
// Undo: move -r 6.337721 0 0
// Undo: select -r pSphere2
// Undo: rotate -r -ws 0 20.345198 0
select -cl ;


Translate pSphere2 in the x dirrection and pSphere1 should move in the z dirrection.... now rotate psphere2 45 degrees and try to translate pSphere2 on the x axis... now, the pSphere1 moves in the exact same dirrection as the first time... I am trying to figure out how to make it translate in the new dirrection ( like the translate z on the loca axis) Hope this helps explain my problem. THanks,
Brian

brianellebracht
05-06-2003, 09:17 PM
I noticed that when you change the translate order to local instead of world, and then you translate the object it adds this to the mel script "-wd " like this.. " move -r -os -wd 0 0 -0.897306" Is there away to incorperate this into the expression so that it dosen't translate on the world axis?
Brian

mark_wilkins
05-06-2003, 09:20 PM
You wrote:

expression -s "if (pSphere1.translateZ)\r\n pSphere1.translateZ;\r" -o pSphere1 -ae 1 -uc all ;


This expression

if (pSphere1.translateZ)
pSphere1.translateZ;

isn't valid syntax and yields an error. What did you mean to do?

-- Mark

brianellebracht
05-06-2003, 09:24 PM
I just coppied my script editor and pasted it in here so you could copy it and execute it. sorry it didn't work, this was the expression

just create two spheres and put this as an expression for the translate z on pSphere1

pSphere1.translateZ=pSphere2.translateX

its really basic, just to show, that if I rotate sphere 1 in the y axis, it still moves on the global z axis, instead of its local z.
Thanks,
B

brianellebracht
05-06-2003, 09:28 PM
BTW thanks for your help Mark :)

mark_wilkins
05-06-2003, 09:31 PM
Changing translate x does not move the object along the world space x axis.

now that I've got that out of my system.

The coordinate space in which translate X moves the object is in the PARENT'S space. In your example, the parent's space happens to be world space, but that's not generally the case. So, for example, if you make two spheres:

sphere -name test1;
sphere -name test2;
parent test2 test1;
rotate 0 45 0 test1;
setAttr test2.tx 5;

see, rotating the *parent* has changed the axis along which the object translates.

Put another way, translations happen before rotations when applying the transform attributes to the object. This is so that you can rotate the object in place after you've moved it, using the default pivot. (If the transformation order happened otherwise, rotating the object would make it sweep through space around the origin, much like rotating the parent object does in this example.)

And no problem, I'm happy to help. :D

-- Mark

brianellebracht
05-06-2003, 10:11 PM
I am sorry!:rolleyes: I see what you mean! I just tried it ouy and it works fine... THanks alot for your help,
Brian E

mark_wilkins
05-06-2003, 10:14 PM
Why not just use a motion path? It really, truly, actually will keep the object oriented along its axis of motion, and requires no complex set-up.

It sounds like what you're really trying to do is stick the parent space's rotate pivot to an object that's moving around in 3D space. You could always try grouping the object, forcing the group's rotate pivot to follow your object in the expression, and then translating around, but whether you'd get what you think you'd get (or whether Maya will even let you do that) is an open question.)

-- Mark

brianellebracht
05-06-2003, 10:35 PM
well, I was just writting a series of commands to contoll tank treds, on well.. a tank. so that when I moved it in a certain dirrection either forward or backwards, the treds would allways move in the correct dirrection at the correct speed. also if i were to rotate the tank, then the treds would also work in the correct dirrection, by oneside moving in the oppisite as the other. But.... IT works!! All I had to do was create a box, that controlled the rotation of the tank, and now the treds allways move in the correct dirrection. Can't really use motion paths to control tank treds, I know I can just animate the treds by normal means, I just wanted to see if I could get expressions to work for this. Took more time figuring out how to get the expressions to work, then it probably would have just animating it by hand. The big thing with the expression for me is that if the tank slows down, the treds automatically slow down and stuff as well. THanks.
Brian

mark_wilkins
05-06-2003, 10:44 PM
well, one way to do that is to calculate world space speed along your axis of movement and then use that to control an attribute that drives the tank tread rotation. So you don't use the treads to drive the tank's movement, you use the tank's movement to drive the treads.

-- Mark

brianellebracht
05-06-2003, 10:53 PM
thats what i did. When I wrote the expresion the first time, I made it so that whenever i moved a locator in the x axis then the treds would move in the correct dirrection and speed. But it didn't work when I turned the tank and moved it continued to move it. i didn't have it parrented to something like a locator that controlled the rotation of the tank. I applied the theory of the test objectst that you had mentioned before, to my tank, by parrenting the tank to a locator, and rotating the locator instead of the tank when I wanted it to turn, the treds now work no matter what dirrection that the tank is pointing in. THanks,
Brian

CGTalk Moderation
01-15-2006, 03:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.