Jump to content

Expression problems


Recommended Posts

I am currently working on a Houdini assignment from 3dBuzz's site and have hit a brick wall with it. We are to model a door that swings like a saloon door and then a ball will roll to it and cause it to swing open. Then when the ball rolls back the other way, the doors will swing open the opposite way. This is a reactive animation by using a spare channel. Oh yeah, we can only use 6 sops! I set everything up in 6 sops and the doors swing open in the one direction but I am having trouble with getting the doors to swing the other way. I already used my 6 sops so can't use a switch sop. My question is, would I be able to put an expression in the doors ry that would use the positive direction of my spare channel keys when moving the ball from the negative side of the door to the positive and then switch to a negative direction when going from the positive side of the door to the negative side? This would be using one transform. I'll attach my file to show what I have done so far. I banged my head arround this for 2 days now and have hit a brick wall. I just need a little nudge to get in the right direction. Thanks.

I did get this to work but it took me 11 sops.

I forgot to say that this is not keyframed so if you hit the play button, nothing will happen. You need to go to the tx of the xfrmBall and move the ball towards the door and the doors will swing open.

Door.zip

Link to comment
Share on other sites

I tried an if expression in the ry channel of the xfrmLftDoor; but it wasn't using (DIRECTION_IS POSITIVE) format. I used something like if(x>-3, chf("Rotation", ch("../xfrmBall/tx")), -chf("Rotation", -ch("../xfrmBall/tx"))) and it didn't work. Should I use:

if(x==positive, chf("Rotation", ch("../xfrmBall/tx")), -chf("Rotation", -ch("../xfrmBall/tx"))) or do I need to have a number in the first part? And would I put it in the ry of the xfrmLftDoor? I've never programmed or wrote expressions before and I am stumped. Do I need to write a custom expression or is that only if you want to make a global variable?

Link to comment
Share on other sites

Ok, I took a quick look at your hip file. The problem it seems to me is that you need to know from which _direction_ your ball is approaching the doors. Not whether the ball is behind or in front of the doors. You'll have no way of knowing that unless you've keyframed your xfrmBall/tx channel first. After that, you can then figure it out. As this is an assignment, I won't give everything away just yet. ;)

Link to comment
Share on other sites

I used the xfrmBall/tx parameter as the Time and moved the xfrmLftDoor open and added keys this way until the ball passed through and the door closed to 0 again. If you go into the channel editor and look for "rotation" which is my spare channel I made, the keys are set in there. Then I linked the doors ry channel to this spare channel I called rotation. So, when the ball rolls from the negative number to the positive, the doors swing open properly. I have that part working (you need to click on the xfrmBall/tx and move the tx and not the playbar to see this happen). I can't seem to get the doors to swing the other way when the ball moves from the positive to negative. As I said, I can't add anymore sops; I have to do this in 6 sops. I did get this working but I had a total of 11 sops. I don't think I am writing out the "which_direction_ball is approaching the doors. I know the chf("Rotation", ch("../xfrmBall/tx")) swings the doors when going from neg to pos and the -chf("Rotation", -ch("../xfrmBall/tx")) would swing the doors properly when moving from pos to neg. I just can't seem to get this working without adding more transforms (for the neg chf) and a switch sop. Maybe I'll just need to stop tonight and look at it fresh in the morning.

Link to comment
Share on other sites

No, your xfrmBall/tx needs to have a channel. Read what I wrote above a little slower ...

By having a channel, do you mean I need to set a keyframe at different frames for the xfrmBall/tx? We aren't allowed to set keys that way. We are to use the xfrmBall/tx as the Time rather than using a frame number as the Time. So as I move the tx of the ball, the door will move to the spot I typed into the key in the spare channel. I followed the steps close to what Buzz did in his vtm only he used a switch sop and another transform and he used 7 sops for one door. I have 2 doors(saloon type) so have reached my 6 sops already without using the switch and more transforms.

I'm sorry, I'm just not getting expressions that well. Maybe this isn't for me. I'm getting very frustrated right now.

Link to comment
Share on other sites

Offhand, I have no idea how you can do what you've set up in the above hip file without keying xfrmBall/tx first. If you're changing the parameter manually, it's extremely hard without CHOPs to determine the current direction of your ball. (notice I said direction, not position).

Link to comment
Share on other sites

Thanks for your help Edward. Here's my file that I got this to work in, but it has 11 sops. I don't know how to do it in 6 sops.

Whenever I open this file I keep getting an "Empty Function" message at the bottom but I just hit cancel and everything loads fine. I don't know what that message means but I get it off and on with the latest build.

Door2.zip

Link to comment
Share on other sites

In that case, why not just make use of doorRotation() in the if expression?

The doorRotation is my own custom expression that I couldn't get to work. When I did get it to work (but not the way I wanted it to), I put this in the ry of the door: doorRotation (ch("../xfrmBall/tx")) and got an error on the xfrmLftDoor Sop. I think I am writing the part where I want to say "when the ball goes from neg to pos I want this to happen, or else that". It's the "when the ball goes from neg to pos" that I'm having trouble with.

I'll look at this again today.

Edit: Just to let you know, I got this to work. I finally got my custom expression to write successfully; although it didn't work when I put it in the ry of my door. A fellow Buzz student showed me what was wrong in my custom expression (which I would not have figured out on my own) and now it works. I'm glad it works because I was getting very frustrated.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...