J.Santos Posted May 20, 2010 Share Posted May 20, 2010 (edited) Hi guys! I need to do a sort of piston assembly, that consists of 2 cilinders/pistons... while one goes up theother goes down and vice-versa. Of course that negating the value of one piston (in ty), thus making the other -ty doesn't do the trick! The other one will go down and it will even start to go up, but only to the minimum value of the other. I need something that allows me to say: If the other one is going up, you will go down but if the other one starts to descend, you'll start to rise... Ok, ok... I need (probably) an if statement... But I didn't managed to make it work properly...I tried to fit the value the other piston would have to assume but without sucess... Can someone explain me how to do it or if there's a different way (in Max you would use some look at constraints or something similar and so on... but here the look at is at Scene level ) I'll attache my file... piston.hipnc Thanks in advance for your time! Edited May 20, 2010 by J.Santos Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted May 20, 2010 Share Posted May 20, 2010 if(ch("../xform5/ty") > 0, -ch("../xform5/ty"), if(ch("../xform5/ty") < 0, abs(ch("../xform5/ty")), ch("../xform5/ty"))) Quote Link to comment Share on other sites More sharing options...
J.Santos Posted May 21, 2010 Author Share Posted May 21, 2010 Hi Swann! Thanks man! I was thinking "How can I add an else here?... Of course, an if inside another... duh to me!!! In the meantime I thought of another soluction, that doesn't involve expressions and probably will work better for what I want... but anyway, this will be great for future references!!! Thanks again man!!! Quote Link to comment Share on other sites More sharing options...
J.Santos Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) Hi again! I ended up using this expression to solve my piston problem: if(ch("../master/constraintBack") >= 0.35, 0.8 - ch("../master/constraintBack"), (0.25 / ch("../master/constraintBack") - 0.3)) someone might be interested... Swann's code works like a charm but (as far as I could test and try it out) only if the values range from positive to negative (and so the use of abs( ) to change the value). Since in my piston the values go from 0.1 to 0.8 I had to use a different approach... I hate having to use "magic numbers" but they are all logical (IMO ) 0.8 as the maximum value/height in ty, 0.35 as the average(half...) of 0.7 and the 0.3... no ideia! But it worked... there's a small "jump, but it's so small that probably will not be noticed and can be hidden... This might not be the best solution but it worked for me so I'm quite happy! Once again my thanks to Swann that teached me a bit more... Edited May 21, 2010 by J.Santos Quote Link to comment Share on other sites More sharing options...
anim Posted May 21, 2010 Share Posted May 21, 2010 (edited) i am not sure what you are doing and how your expression behaves in your scene, but when i tried it it prodices values from 2.2 to 0 if you just want to reverse the piston movement you can just use fit(ch("./constraintBack"), 0.1,0.8,0.8,0.1) but maybe i've missed your intention Edited May 21, 2010 by anim Quote Link to comment Share on other sites More sharing options...
Guest Swann Posted May 21, 2010 Share Posted May 21, 2010 (edited) or just paste this 0.9-ch("constraintBack") into your master control frontPiston field instead of your expression. Edited May 21, 2010 by SWANN Quote Link to comment Share on other sites More sharing options...
J.Santos Posted May 21, 2010 Author Share Posted May 21, 2010 Hi Anim! Yeap... those are the values Confused? So was I... but I forgot to mention that I did constrained the values (or rather the range) to never go below 0.1 or above 0.8... so the rest of the values could be produced (and indeed are) but in my animation that's seamless... I know that's not the most efficient way and I'm "throwing" away those poor old values that are out f my range but... it worked! But now I can remake the expression to be more efficient! And with that I learned something... Thanks for your expression I'll try it out tomorrow! Hi Swann! Thanks for your follow up... and yeap, I think you hit the nail with that expression! Really simple and should work well...I'll try it tomorrow and post the results! Thanks! This only proves that the simple ways are always better... Thanks again to both of you guys! Have a great weekend!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.