Jump to content

random translation in for loop


isah_voodoo

Recommended Posts

I am trying to randomly translate on the y axis using a for loop. I have successfully randomized the color but for some reason I can't move them upwards.

int i=0;
vector rand=rand(@class*234.234);
f@randY=fit01(rand(@id*234.234),2, 12);


for(i; i<10; i+=1){
    v@Cd=rand;
    @P.y=@randY;   
}

 

What am I doing wrong here?

translate_forloop.hipnc

Link to comment
Share on other sites

There's a couple of things here you need to fix.

First, a Wrangle, unless it's in Detail mode, is inherently a kind of for-each loop that runs in parallel. So if you're just trying to bump each primitive up by a random amount, you don't need a for loop in here; the wrangle itself will generate a new random value per id.

Second, the @P attribute of a primitive is only a sort of pseudo-attribute; it's not writeable the way the point attribute @P is. You'll want to edit point positions in a point wrangle instead. If you want to move each box randomly upwards, you have two good options: you can move the template points before the Copy SOP, or you can pack and instance the boxes and then move them in a Point Wrangle, since a packed object effectively works like a point.

  • Like 1
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...