Jump to content

Need help with simple VEX function


BlackPariah

Recommended Posts

Hello!

New Houdini user here with barely 3 weeks in... so please bare with me :D 

I'm trying to write a small VEX function/expression to translate an object along it's Y axis by an exponential function... like gravity.

The math behind is simple but I'm having trouble expressing it in VEX...

I tried the following line with a VEX attribute wrangle node on a default sphere and it's giving me errors and the sphere just disappears on the 1st frame:    t.y = t.y + (9.8 * ($T ^ 2));

If someone could steer me in the right direction I would appreciate it thank you :-)

 

 

Link to comment
Share on other sites

Use the good attributes see here http://www.sidefx.com/docs/houdini15.5/vex/snippets#attributes

For your case the good expression is this:

@P.y = @P.y + 9.8 * pow(@Time, 2);

and you can simplify with:

@P.y += 9.8 * pow(@Time, 2);

But if you want a gravity effect, subtract is the better way ;)

Edited by fsimerey
Link to comment
Share on other sites

I think this is what you are looking for

float gravity = 9.8; 
@P.y += gravity * (pow(@Time, 2));

I believe the "$" expression isn't valid in Vex, however you can use it in hscript ... check out the help docs to see what is the correct syntax for Vex.

http://www.sidefx.com/docs/houdini15.5/vex/snippets

 

 

Edited by Sepu
Link to comment
Share on other sites

Wow great stuff thank you guys :D I ran into one small issue now... & the object in question will keep accelerating forever with this method.

My guess is I would need some kind of a loop or if / then structure to define a maximum limit of the result... I'm not numerically inclined so it's difficult for me to put it in numbers... more so with VEX.

Maybe I'm way over my head with this but it would help a lot if I could see an example of how to structure the code... if it's not asking too much I'd appreciate it thank you again :D

Edited by BlackPariah
Link to comment
Share on other sites

float gravity = pow(@Time, 2);
if (@Time > ch("limit")) {
    float increment = pow(ch("limit"), 2) - pow(ch("limit") - @TimeInc, 2);
    gravity =  pow(ch("limit"), 2) + increment * ((@Frame - ch("limit") / @TimeInc) - 1);
    }
@P.y += -9.8 * gravity;

Here an example.

The limit is a time value in seconds. Don't forget to click on the white button on the right of the editor area to spare parameter.

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...